Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Remove workarounds no longer relevant in 4.10.2 release of Transformers, closes #110

davidmezzetti652a494e4a6c
diff --git a/setup.py b/setup.py
index 1c4d8e93..ef6451c4 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as f:
DESCRIPTION = f.read()
# Required dependencies
-install = ["faiss-cpu>=1.7.1.post2", "numpy>=1.18.4", "torch>=1.6.0", "transformers>=4.8.2"]
+install = ["faiss-cpu>=1.7.1.post2", "numpy>=1.18.4", "torch>=1.6.0", "transformers>=4.10.2"]
# Optional dependencies
extras = {}
diff --git a/src/python/txtai/models/onnx.py b/src/python/txtai/models/onnx.py
index 50453fff..dd76a650 100644
--- a/src/python/txtai/models/onnx.py
+++ b/src/python/txtai/models/onnx.py
@@ -68,16 +68,13 @@ class OnnxModel(PreTrainedModel):
"""
# pylint: disable=W0212
- if hasattr(mapping, "_config_mapping"):
- Params = namedtuple("Params", ["config", "model"])
- params = Params(key, value)
-
- mapping._modules[key] = params
- mapping._config_mapping[key] = "config"
- mapping._reverse_config_mapping[value] = key
- mapping._model_mapping[key] = "model"
- else:
- mapping[key] = value
+ Params = namedtuple("Params", ["config", "model"])
+ params = Params(key, value)
+
+ mapping._modules[key] = params
+ mapping._config_mapping[key] = "config"
+ mapping._reverse_config_mapping[value] = key
+ mapping._model_mapping[key] = "model"
def forward(self, **inputs):
"""
diff --git a/src/python/txtai/pipeline/labels.py b/src/python/txtai/pipeline/labels.py
index fa83c9e4..bebc4cf0 100644
--- a/src/python/txtai/pipeline/labels.py
+++ b/src/python/txtai/pipeline/labels.py
@@ -18,9 +18,6 @@ class Labels(HFPipeline):
# Set if labels are dynamic (zero shot) or fixed (standard text classification)
self.dynamic = dynamic
- # Save handle to pipeline tokenizer
- self.tokenizer = self.pipeline.tokenizer
-
def __call__(self, text, labels=None, multilabel=False):
"""
Applies a text classifier to text. Returns a list of (id, score) sorted by highest score,
@@ -41,14 +38,8 @@ class Labels(HFPipeline):
"""
if self.dynamic:
- # Override tokenizer to set truncation parameter
- self.pipeline.tokenizer = self.tokenize
-
# Run zero shot classification pipeline
results = self.pipeline(text, labels, multi_label=multilabel, truncation=True)
-
- # Reset tokenizer
- self.pipeline.tokenizer = self.tokenizer
else:
# Run text classification pipeline
results = self.textclassify(text, multilabel)
@@ -103,18 +94,3 @@ class Labels(HFPipeline):
"""
return list(self.pipeline.model.config.id2label.values())
-
- def tokenize(self, *args, **kwargs):
- """
- Tokenization method that forces truncation=True.
-
- Args:
- args: arguments
- kwargs: named arguments
-
- Returns:
- tokenized output
- """
-
- kwargs["truncation"] = True
- return self.tokenizer(*args, **kwargs)
diff --git a/test/python/testonnx.py b/test/python/testonnx.py
index 0c6ed9aa..62a29f2a 100644
--- a/test/python/testonnx.py
+++ b/test/python/testonnx.py
@@ -58,12 +58,6 @@ class TestOnnx(unittest.TestCase):
self.assertTrue("key" in mapping._model_mapping)
self.assertTrue("key" in mapping._modules)
- # Test mapping backed by dict
- mapping = {}
- model.autoadd(mapping, "key", "value")
-
- self.assertTrue("key" in mapping)
-
def testDefault(self):
"""
Test exporting an ONNX model with default parameters