File size: 917 Bytes
af2a34a
 
b94b64a
8053249
af2a34a
8053249
af2a34a
 
0ff9065
af2a34a
 
 
 
 
 
 
 
0ff9065
af2a34a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from transformers import pipeline
import pandas as pd

# Load the dataset
df = pd.read_csv("marksverdhei/wordnet-definitions-en-2021")

# Initialize the question-answering pipeline
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="distilbert-base-cased")

# Function to find the definition of a word
def find_definition(question):
    word = question.split(" ")[-1]  # Extract the word from the question
    definition = df[df['word'] == word]['definition'].values.tolist()
    if definition:
        return definition[0]
    else:
        return "Sorry, I couldn't find a definition for that word."

# Main loop for interacting with the chatbot
while True:
    user_input = input("You: ")
    if user_input.lower() == "exit":
        print("Goodbye!")
        break
    else:
        definition = find_definition(user_input)
        print("Chatbot:", definition)