Open xiulinyang opened 3 days ago
Hello @xiulinyang it is hard to tell without a runnable example to reproduce the error. But I would suspect the error lies somewhere in the way you read the sentences.
Some ideas:
Hi @alanakbik, thanks a lot for your prompt reply! :)
I tried to use ColumnCorpus in Flair (as seen below) but the issue remains. Is it possible for me to send you the code, training log and the data for reproduce the error? Or is there anything that I misunderstood in the code below? Thanks!
def predict(self, in_path=None, as_text=False):
model = self.model
if as_text:
data = in_path
#data = (data + "\n").replace("<s>\n", "").replace("</s>\n", "\n").strip()
else:
data = io.open(in_path,encoding="utf8").read()
true_tags = []
data = data.strip() + "\n" # Ensure final new line for last sentence
for line in data.split("\n"):
if "\t" in line:
true_tags.append(line.split("\t")[7])
columns = {0: "text", 1: "upos", 2: "deprel", 3: "attach", 4: "arg1", 5: "arg2", 6: "arg3", 7: "ner"}
corpus: Corpus = ColumnCorpus(data_folder, columns, train_file="train.biodep.sample.tab",
test_file="test.biodep.sample.tab", dev_file="dev.biodep.sample.tab", )
output = []
toknum = 0
model.predict(corpus.dev, force_token_predictions=True, return_probabilities_for_all_classes=True))
for sentence in corpus.dev:
for token in sentence:
text = token.text
if len(token.labels) > 6:
ner_tag = token.labels[6].value
ner_value = token.labels[6].score
else:
ner_tag = "O"
ner_value = "1.0"
corr = 'T' if ner_tag == true_tags[toknum] else 'F'
output.append(text+'\t'+true_tags[toknum]+'\t'+ner_tag+ '\t'+ corr +'\t' + ner_value)
toknum +=1
partition = "test" if "test" in in_path else "dev"
with io.open(script_dir + TRAIN_PATH +os.sep + "flair-"+partition+"-pred.tsv",'w',encoding="utf8",newline="\n") as f:
f.write("\n".join(output))
Question
Hi,
I'm training a SequenceTagger to do the NER task using my customed dataset with the customed features. After training was done, I got a file named test.tsv which is the prediction of the test split. However, when I loaded the trained model (final-model.pt) and did inference on the same test data, I got way lower results (0.86 vs 0.64 in accuracy).
Here is the prediction function I'm using. I checked the sents list, and all the labels are correctly added to each token. During training, I stacked all the features - should I do the same during prediction? I find the main issue is that the model does not understand the labels added - I have a specific label named
__TARGET__
which is the signal for the model to give predictions on specific tokens, but it seems that the model ignores the tag. It would be very appreciated for any suggestions. Thanks!