Exemplo n.º 1
0
    async def predict(
            self, sources: SourcesContext
    ) -> AsyncIterator[Tuple[Record, Any, float]]:
        if not self.is_trained:
            raise ModelNotTrained("Train model before prediction.")

        async for record in sources.records():
            doc = self.parent.nlp(record.feature("sentence"))
            prediction = [(ent.text, ent.label_) for ent in doc.ents]
            record.predicted("Tag", prediction, "Nan")
            yield record
Exemplo n.º 2
0
    async def predict(
            self, sources: SourcesContext
    ) -> AsyncIterator[Tuple[Record, Any, float]]:
        if not os.path.isdir(os.path.join(self.parent.config.output_dir,
                                          "ner")):
            raise ModelNotTrained("Train model before prediction.")
        self.nlp = spacy.load(self.parent.config.output_dir)

        async for record in sources.records():
            doc = self.nlp(record.feature("sentence"))
            prediction = [(ent.text, ent.label_) for ent in doc.ents]
            record.predicted("Tag", prediction, "Nan")
            yield record
Exemplo n.º 3
0
 async def score(self, mctx: ModelContext, sources: SourcesContext,
                 feature: Feature):
     accuracy: int = 0
     async for record in sources.records():
         accuracy += int(record.key)
     return accuracy