TypeError
Opened this issue · 3 comments
FayeXXX commented
There is a bug in styletransformer/seq2seq.py line 350, which is :
"{TypeError}can only concatenate str (not "list") to str"
I think the result["gen"][i] should be the sentence instead of token list
thangld201 commented
hzhwcmhf commented
@thangld201 I am not sure where is the problem... Is the output correct after modifying this line?
thangld201 commented
@hzhwcmhf There are two parts that I had to change:
+) Line 350-351 to:
show_str.append(f"sent{domain}:" + " ".join(result["sgen"][i]))
show_str.append(f"gen{domain}:" + " ".join(result["gen"][i]))
+) Line 397-403 to:
with open(f"{output_dir}/{self.now_batch}.neg2pos.txt", 'w') as f:
for sent in result0["gen"]:
f.write(' '.join(sent)+ "\n")
with open(f"{output_dir}/{self.now_batch}.pos2neg.txt", 'w') as f:
for sent in result1["gen"]:
f.write(' '.join(sent)+ "\n")
The reasons being result["gen"][i]
,result["sgen"][i]
and sent
are all list of words (e.g. ["I","have","seen","this","cake"] instead of "I have seen this cake"), so they need to be formatted as string before writing to files like this.