将torchtext.data改成torch.legacy.data
TEXT = torchtext.legacy.data.Field(sequential = True ,tokenize = tokenizer,lower =True, fix_length = MAX_LEN,postprocessing = filterLowFreqWords)
python - 属性错误 :module 'torchtext.data' has no attribute 'TabularDataset'问题二、
``
解决:
def filterLowFreqWords(ARR,VOCAB):
arr = [[x if x
改成
def filterLowFreqWords(arr,vocab):
arr = [[x if x
括号传参问题
问题三、
改成:
添加:
import torchmetrics
metric = torchmetrics.Accuracy()
生成两组与prediction形状相同的矩阵,然后按照prediction是否大于0.5,是,选1,否,选0,即将预测结果四舍五入为0或1
问题四、
这句话有错误,打印不出来
错误提示:
解决:
训练模型时候:
添加:
metric = torchmetrics.Accuracy()
注释掉:
#acc = pl.metrics.functional.accuracy(preds, y)
改成:
acc = metric(preds, y.int())
就可以了



