Microsoft 365 and Office | Development | Other
Building custom solutions that extend, automate, and integrate Microsoft 365 apps.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When I run the debugger in my code I get the error 'Cannot get dimension 'nO' for model 'sparse_linear': value unset'. Ive tried uninstalling, reinstalling, updating both spaCy, thinc and python, but none of these seems to work. Ive ran a print to see if a test sentence was being tokenized, in which it was, showing spaCy is being loaded. If anyone could help me here I would but very greatful. thanks
import random
import openai
from collections import defaultdict
import speech_recognition as sr
import spacy
from spacy.training.example import Example
openai.api_key = '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'
nlp = spacy.load("en_core_web_lg")
nlp_textcat = spacy.blank("en")
doc = nlp("This is a test sentence. Let's")
for token in doc:
print(token.text, token.pos_)
# Text Classification Pipeline Component
config = {
"threshold": 0.5, # Adjust the threshold as needed
# Set to True if each text should belong to only one category
"exclusive_classes": False,
"architecture": "simple_cnn", # You can experiment with different architectures
}
# Add the TextCategorizer to the pipeline
textcat = nlp_textcat.add_pipe("textcat")
recognizer = sr.Recognizer()
TRAINING_DATA = [
("What aisle is pest control in?", {
"cats": {"locate_product": 1, "other_intent": 0}}),
("Tell me where I can find gardening supplies.", {
"cats": {"locate_product": 1, "other_intent": 0}}),
("where can I find paint?.", {
"cats": {"locate_product": 1, "other_intent": 0}}),
]
def setup_intent_recognition(nlp):
# Create a TextCategorizer component if it doesn't exist
if "textcat" not in nlp.pipe_names:
textcat = nlp.add_pipe("textcat")
else:
textcat = nlp.get_pipe("textcat")
# Define intent labels
textcat.add_label("locate_product")
textcat.add_label("other_intent")
# Add labels for your specific intents
# For example:
# textcat.add_label("order_product")
# textcat.add_label("cancel_order")
setup_intent_recognition(nlp_textcat)
random.shuffle(TRAINING_DATA)
for text, annotations in TRAINING_DATA:
example = Example.from_dict(nlp_textcat.make_doc(text), annotations)
nlp_textcat.update([example], drop=0.5)
# Manually configure the TextCategorizer
textcat = nlp_textcat.get_pipe("textcat")
textcat.cfg["threshold"] = 0.5 # Adjust the threshold as needed
# Set to True if each text should belong to only one category
textcat.cfg["exclusive_classes"] = True
# You can experiment with different architectures
textcat.cfg["architecture"] = "simple_cnn"
# Add the text classification component to the pipeline
nlp_textcat.add_pipe(textcat, last=True)
Building custom solutions that extend, automate, and integrate Microsoft 365 apps.