我已经训练了一个模型。现在我想导出它的输出类型(str)。我如何将它的输出结果保存在 Dataframe 或任何其他形式中,以便将来使用。
gf = df['findings'].astype(str)
preprocess_text = gf.str.strip().replace("\n","")
t5_prepared_Text = "summarize: "+preprocess_text print ("original text preprocessed: \n", preprocess_text)
tokenized_text = tokenizer.encode(str(t5_prepared_Text, return_tensors="pt").to(device)
# summmarize
summary_ids = model.generate(tokenized_text, num_beams=4, no_repeat_ngram_size=2, min_length=30, max_length=100, early_stopping=True)
output = tokenizer.decode(summary_ids[0], skip_special_tokens=True) print ("\n\nSummarized text: \n"
模型输出
0 summarize: There is XXXX increased opacity wit...
1 summarize: There is XXXX increased opacity wit...
2 summarize: There is XXXX increased opacity wit...
3 summarize: Interstitial markings are diffusely...
4 summarize: Interstitial markings are diffusely...
5 summarize: nan
6 summarize: nan
Name: findings, dtype: object:
到目前为止我已经试过这样
prediction = pd.DataFrame([text]).to_csv('prediction.csv')
但是它将所有这些行保存在csv的一个单元格(第一个单元格)中,并且都是如下所示的半形式。
0 summarize: There is XXXX increased opacity wit...
1 summarize: There is XXXX increased opacity wit...
2 summarize: There is XXXX increased opacity wit...
3 summarize: Interstitial markings are diffusely...
4 summarize: Interstitial markings are diffusely...
5 summarize: nan
6 summarize: nan
Name: findings, dtype: object:
1条答案
按热度按时间mlnl4t2r1#
把这个换掉
有了这个