mbochniak01 Claude Sonnet 4.6 commited on
Commit ·
86cfc1b
1
Parent(s): b2eeefb
Fix Vectara pipeline: explicitly load tokenizer before pipeline init
Browse filestransformers<4.46 can't auto-detect the tokenizer for Vectara's custom
HHEMv2 architecture, leaving pipeline.tokenizer as None at inference.
Loading AutoTokenizer explicitly and passing it in resolves the TypeError.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Dockerfile +3 -2
- backend/grader.py +3 -1
Dockerfile
CHANGED
|
@@ -13,9 +13,10 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 13 |
# Pre-download models so first request isn't slow on HF Spaces
|
| 14 |
RUN python -c "\
|
| 15 |
from sentence_transformers import SentenceTransformer; \
|
| 16 |
-
from transformers import pipeline; \
|
| 17 |
SentenceTransformer('all-MiniLM-L6-v2'); \
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
COPY knowledge/ ./knowledge/
|
| 21 |
COPY backend/ ./backend/
|
|
|
|
| 13 |
# Pre-download models so first request isn't slow on HF Spaces
|
| 14 |
RUN python -c "\
|
| 15 |
from sentence_transformers import SentenceTransformer; \
|
| 16 |
+
from transformers import AutoTokenizer, pipeline; \
|
| 17 |
SentenceTransformer('all-MiniLM-L6-v2'); \
|
| 18 |
+
tok = AutoTokenizer.from_pretrained('vectara/hallucination_evaluation_model', trust_remote_code=True); \
|
| 19 |
+
pipeline('text-classification', model='vectara/hallucination_evaluation_model', tokenizer=tok, trust_remote_code=True)"
|
| 20 |
|
| 21 |
COPY knowledge/ ./knowledge/
|
| 22 |
COPY backend/ ./backend/
|
backend/grader.py
CHANGED
|
@@ -16,7 +16,7 @@ from typing import Any
|
|
| 16 |
|
| 17 |
from sentence_transformers import SentenceTransformer
|
| 18 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 19 |
-
from transformers import pipeline as hf_pipeline
|
| 20 |
|
| 21 |
from config import EMBEDDER_MODEL
|
| 22 |
from rosetta import check_terminology
|
|
@@ -41,9 +41,11 @@ def get_nli_model() -> Any:
|
|
| 41 |
"""Return the shared Vectara faithfulness pipeline, loading it on first call."""
|
| 42 |
global _nli_model
|
| 43 |
if _nli_model is None:
|
|
|
|
| 44 |
_nli_model = hf_pipeline(
|
| 45 |
"text-classification",
|
| 46 |
model=NLI_MODEL,
|
|
|
|
| 47 |
trust_remote_code=True,
|
| 48 |
truncation=True,
|
| 49 |
max_length=512,
|
|
|
|
| 16 |
|
| 17 |
from sentence_transformers import SentenceTransformer
|
| 18 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 19 |
+
from transformers import AutoTokenizer, pipeline as hf_pipeline
|
| 20 |
|
| 21 |
from config import EMBEDDER_MODEL
|
| 22 |
from rosetta import check_terminology
|
|
|
|
| 41 |
"""Return the shared Vectara faithfulness pipeline, loading it on first call."""
|
| 42 |
global _nli_model
|
| 43 |
if _nli_model is None:
|
| 44 |
+
tokenizer = AutoTokenizer.from_pretrained(NLI_MODEL, trust_remote_code=True)
|
| 45 |
_nli_model = hf_pipeline(
|
| 46 |
"text-classification",
|
| 47 |
model=NLI_MODEL,
|
| 48 |
+
tokenizer=tokenizer,
|
| 49 |
trust_remote_code=True,
|
| 50 |
truncation=True,
|
| 51 |
max_length=512,
|