Test_Bot / key_words.py
aguyader's picture
Upload folder using huggingface_hub
f307bb6 verified
raw
history blame contribute delete
683 Bytes
import spacy
from spacy.lang.en.stop_words import STOP_WORDS
# Load spaCy's English language model
nlp = spacy.load('en_core_web_sm')
def extract_keywords(question):
# Process the question using spaCy NLP pipeline
doc = nlp(question)
# Extract keywords by removing stopwords, punctuation, and selecting nouns/adjectives
keywords = [token.text for token in doc if token.is_stop == False and token.is_punct == False and token.pos_ in ['NOUN', 'ADJ', 'VERB']]
return keywords
# Example chatbot question
question = "What is the weather like in New York City today?"
# Extract keywords
keywords = extract_keywords(question)
print("Keywords:", keywords)