Download training.py from Kavi11/ChatBot: direct link, hf CLI and curl.
- Browser
- Download file 868 Bytes
-
https://huggingface.co/spaces/Kavi11/ChatBot/resolve/main/training.py
- Command line
-
hf download hf://spaces/Kavi11/ChatBot/training.py
-
curl -L -o training.py https://huggingface.co/spaces/Kavi11/ChatBot/resolve/main/training.py
868 Bytes
| import pandas as pd | |
| from sklearn.feature_extraction.text import TfidfVectorizer | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.linear_model import SGDClassifier | |
| from sklearn.metrics import accuracy_score | |
| import joblib | |
| df = pd.read_csv('data.csv') | |
| dataset = pd.concat([df,df],ignore_index=True) | |
| x = dataset['utterance'] | |
| y = dataset['response'] | |
| vectorizer = TfidfVectorizer() | |
| x_tfidf = vectorizer.fit_transform(x) | |
| x_train, x_test, y_train, y_test = train_test_split(x_tfidf,y, test_size=0.20, random_state=42) | |
| model = SGDClassifier(loss='log_loss') | |
| model.fit(x_train, y_train) | |
| y_pred = model.predict(x_test) | |
| accuracy = accuracy_score(y_test,y_pred) | |
| print(f"Accuracy:\n {accuracy*100}% is the accuracy of the chatbot") | |
| joblib.dump(model,'SmallTalk.pkl') | |
| joblib.dump(vectorizer, 'SmallTalkVector.pkl') | |
| loaded_model = joblib.load('SmallTalk.pkl') |