Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
9a28506
1
Parent(s):
3657839
fix truncate
Browse files- app/ner/services/ner.py +6 -13
app/ner/services/ner.py
CHANGED
|
@@ -12,7 +12,11 @@ class NER:
|
|
| 12 |
from optimum.onnxruntime import ORTModelForTokenClassification
|
| 13 |
from optimum.pipelines import pipeline
|
| 14 |
|
| 15 |
-
self.tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
self.model = ORTModelForTokenClassification.from_pretrained(self.model_dir)
|
| 17 |
self.pipeline = pipeline(task=settings.TASK_NAME,
|
| 18 |
model=self.model,
|
|
@@ -23,18 +27,7 @@ class NER:
|
|
| 23 |
if self.pipeline is None:
|
| 24 |
raise ValueError("Model not loaded. Please call load_model() first.")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
text,
|
| 28 |
-
truncation=settings.TRUNCATE,
|
| 29 |
-
max_length=settings.MAX_LENGTH,
|
| 30 |
-
return_tensors="pt"
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
pred = self.model(**inputs)
|
| 34 |
-
|
| 35 |
-
pred = self.pipeline.decode(pred.logits)
|
| 36 |
-
|
| 37 |
-
# pred = self.pipeline(text)
|
| 38 |
|
| 39 |
if entity_tag:
|
| 40 |
return self.extract_entities(pred, entity_tag)
|
|
|
|
| 12 |
from optimum.onnxruntime import ORTModelForTokenClassification
|
| 13 |
from optimum.pipelines import pipeline
|
| 14 |
|
| 15 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 16 |
+
self.model_dir,
|
| 17 |
+
truncation=settings.TRUNCATE,
|
| 18 |
+
max_length=settings.MAX_LENGTH
|
| 19 |
+
)
|
| 20 |
self.model = ORTModelForTokenClassification.from_pretrained(self.model_dir)
|
| 21 |
self.pipeline = pipeline(task=settings.TASK_NAME,
|
| 22 |
model=self.model,
|
|
|
|
| 27 |
if self.pipeline is None:
|
| 28 |
raise ValueError("Model not loaded. Please call load_model() first.")
|
| 29 |
|
| 30 |
+
pred = self.pipeline(text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if entity_tag:
|
| 33 |
return self.extract_entities(pred, entity_tag)
|