File size: 723 Bytes
49f0c5b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import spacy
import jsonlines
# Load the trained model
model_path = "./my_trained_model"
nlp = spacy.load(model_path)
# Load the unlabeled data
unlabeled_data_file = "data/train.jsonl"
# Open the JSONL file and classify each record
classified_data = []
with jsonlines.open(unlabeled_data_file) as reader:
for record in reader:
text = record["text"]
doc = nlp(text)
predicted_labels = doc.cats
classified_data.append({"text": text, "predicted_labels": predicted_labels})
# Optionally, you can save the classified data to a file or process it further
output_file = "data/thirdStep_file.jsonl"
with jsonlines.open(output_file, mode="w") as writer:
writer.write_all(classified_data)
|