Spaces:
Sleeping
Sleeping
Upload threshold.py
Browse files- python_Code/threshold.py +16 -0
python_Code/threshold.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spacy
|
| 2 |
+
|
| 3 |
+
def set_threshold(model_path, threshold):
|
| 4 |
+
# Load the trained model
|
| 5 |
+
nlp = spacy.load(model_path)
|
| 6 |
+
|
| 7 |
+
# Set the threshold for text classification
|
| 8 |
+
nlp.get_pipe('textcat_multilabel').threshold = threshold
|
| 9 |
+
|
| 10 |
+
return nlp
|
| 11 |
+
|
| 12 |
+
# Example usage:
|
| 13 |
+
if __name__ == "__main__":
|
| 14 |
+
model_path = "./my_trained_model"
|
| 15 |
+
threshold = 0.21
|
| 16 |
+
nlp = set_threshold(model_path, threshold)
|