Commit 447a4a5e by Long Duong

polish the code

parent 94c23505
...@@ -106,15 +106,14 @@ class CRFTagger(TaggerI): ...@@ -106,15 +106,14 @@ class CRFTagger(TaggerI):
# We need the list of sentences instead of the list generator for matching the input and output # We need the list of sentences instead of the list generator for matching the input and output
result = [] result = []
for sent in sents: for sent in sents:
features = [] features = [self._get_features(data) for data in sent]
for data in sent:
features.append(self._get_features(data))
labels = tagger.tag(features) labels = tagger.tag(features)
if len(labels) != len(sent): if len(labels) != len(sent):
raise Exception(' Predicted Length Not Matched, Expect Errors !') raise Exception(' Predicted Length Not Matched, Expect Errors !')
tagged_sent = []
for i in range(len(labels)): tagged_sent = [(sent[i],labels[i]) for i in range(len(labels))]
tagged_sent.append((sent[i],labels[i]))
result.append(tagged_sent) result.append(tagged_sent)
return result return result
...@@ -131,11 +130,9 @@ class CRFTagger(TaggerI): ...@@ -131,11 +130,9 @@ class CRFTagger(TaggerI):
y_train = [] y_train = []
for sent in train_data: for sent in train_data:
features = [] features = [self._get_features(data) for data,label in sent]
labels = [] labels = [label for data,label in sent]
for data,label in sent:
features.append(self._get_features(data))
labels.append(label)
X_train.append(features) X_train.append(features)
y_train.append(labels) y_train.append(labels)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment