我已经训练了一个模型。现在我想导出它的输出,也就是type (str)。我如何保存它的输出结果在一个数据框或任何其他形式,我可以使用为将来的目的。
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 ("nnSummarized 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:
把这个
prediction = pd.DataFrame([text]).to_csv('prediction.csv')
与
prediction = pd.DataFrame([text]).to_csv('prediction.csv', sep=";")