Spaces:
Sleeping
Sleeping
Update utils/non_melting_point.py
Browse files- utils/non_melting_point.py +34 -11
utils/non_melting_point.py
CHANGED
|
@@ -28,16 +28,40 @@ class NgramProcessor:
|
|
| 28 |
models = ["en_core_web_trf"]
|
| 29 |
|
| 30 |
# Check and register curated transformer if needed
|
| 31 |
-
if
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Load specified model
|
| 43 |
self.models = {}
|
|
@@ -594,7 +618,6 @@ if __name__ == "__main__":
|
|
| 594 |
|
| 595 |
# Initialize with multiple models
|
| 596 |
processor = NgramProcessor(models=["en_core_web_trf"])
|
| 597 |
-
|
| 598 |
# Process with all models combined
|
| 599 |
common_ngrams,indexed_ngrams = processor.find_filtered_ngrams(sentences)
|
| 600 |
|
|
|
|
| 28 |
models = ["en_core_web_trf"]
|
| 29 |
|
| 30 |
# Check and register curated transformer if needed
|
| 31 |
+
# Fix for registry.get_names error - check if curated_transformer exists in a compatible way
|
| 32 |
+
try:
|
| 33 |
+
# First try to check if "curated_transformer" exists in the registry
|
| 34 |
+
curated_transformer_exists = False
|
| 35 |
+
|
| 36 |
+
# Compatible check across different spaCy versions
|
| 37 |
+
if hasattr(registry, 'factories'):
|
| 38 |
+
if hasattr(registry.factories, 'get_names'):
|
| 39 |
+
# spaCy older version
|
| 40 |
+
curated_transformer_exists = "curated_transformer" in registry.factories.get_names("pipe", "en")
|
| 41 |
+
elif hasattr(registry.factories, 'get'):
|
| 42 |
+
# spaCy newer version - check differently
|
| 43 |
+
pipe_factories = registry.factories.get("pipe", {})
|
| 44 |
+
curated_transformer_exists = "curated_transformer" in pipe_factories
|
| 45 |
+
else:
|
| 46 |
+
# Alternative check if structure is different
|
| 47 |
+
factories_dict = getattr(registry.factories, "__dict__", {})
|
| 48 |
+
for key, value in factories_dict.items():
|
| 49 |
+
if "curated_transformer" in str(key):
|
| 50 |
+
curated_transformer_exists = True
|
| 51 |
+
break
|
| 52 |
+
|
| 53 |
+
if not curated_transformer_exists:
|
| 54 |
+
try:
|
| 55 |
+
# Try to import and register the curated transformer
|
| 56 |
+
import spacy_curated_transformers
|
| 57 |
+
from spacy_curated_transformers import CuratedTransformer
|
| 58 |
+
from spacy.language import Language
|
| 59 |
+
Language.factory("curated_transformer", func=CuratedTransformer)
|
| 60 |
+
tqdm.write("[NgramProcessor] Registered curated_transformer factory")
|
| 61 |
+
except ImportError:
|
| 62 |
+
tqdm.write("[NgramProcessor] Warning: spacy_curated_transformers not found. Some models may not load correctly.")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
tqdm.write(f"[NgramProcessor] Warning: Error checking for curated_transformer: {str(e)}")
|
| 65 |
|
| 66 |
# Load specified model
|
| 67 |
self.models = {}
|
|
|
|
| 618 |
|
| 619 |
# Initialize with multiple models
|
| 620 |
processor = NgramProcessor(models=["en_core_web_trf"])
|
|
|
|
| 621 |
# Process with all models combined
|
| 622 |
common_ngrams,indexed_ngrams = processor.find_filtered_ngrams(sentences)
|
| 623 |
|