Cannot get dimension 'nO' for model 'sparse_linear': value unset

Scotty 0 Reputation points
2023-09-25T02:36:52.65+00:00

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)

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,842 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.