from transformers import BertTokenizer, TFBertModel import numpy as np import pandas as…
- User
from transformers import BertTokenizer, TFBertModel import numpy as np import pandas as pd from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.model_selection import train_test_split from sklearn.svm import SVC from sklearn.metrics import classification_report
Load Quora dataset
quora_data = pd.read_csv('questions.csv', nrows=6000)
Select a subset of the dataset for training
#train_data = quora_data.sample(n=80) # Adjust the number of samples based on your requirements
Get the minimum length between question1 and question2
#min_length = min(len(quora_data['question1']), len(quora_data['question2']))
Adjust the number of samples based on the minimum length
#train_data = quora_data_train.sample(n=5000)
Select the first 5000 samples as the training set
train_data = quora_data[:5000]
Convert the question pairs to list format
question1_list = list(train_data['question1']) question2_list = list(train_data['question2']) is_duplicate = list(train_data['is_duplicate'])
Create DataFrame for the first pair
data1 = pd.DataFrame({'Sentences': question1_list, 'Labels': is_duplicate})
Create DataFrame for the second pair
data2 = pd.DataFrame({'Sentences': question2_list, 'Labels': is_duplicate})
Concatenate the two DataFrames
data = pd.concat([data1, data2], ignore_index=True)
Split data into train and test sets
#X_train, X_test, y_train, y_test = train_test_split(data['Sentences'], data['Labels'], test_size=0.1, random_state=42)
Split data into train and test sets
X_train = data['Sentences'][:5000] X_test = data['Sentences'][1000:] y_train = data['Labels'][:5000] y_test = data['Labels'][1000:]
Initialize the TF-IDF vectorizer
vectorizer = TfidfVectorizer()
Vectorize the sentences in train set
X_train_vectors = vectorizer.fit_transform(X_train)
Vectorize the sentences in test set
X_test_vectors = vectorizer.transform(X_test)
Initialize the SVM classifier
svm = SVC()
Fit the classifier to the training data
svm.fit(X_train_vectors, y_train)
Predict labels for the test data
y_pred = svm.predict(X_test_vectors)
Print classification report
print(classification_report(y_test, y_pred))
from sklearn.metrics import accuracy_score, confusion_matrix, precision_score, f1_score, recall_score
Calculate metrics
accuracy = accuracy_score(y_test, y_pred) cm = confusion_matrix(y_test, y_pred) precision = precision_score(y_test, y_pred) f1 = f1_score(y_test, y_pred) recall = recall_score(y_test, y_pred)
- Assistant
To modify the code to make the test on 1000 pairs, you can update the following lines of code:
# Split data into train and test sets X_train = data['Sentences'][:5000] X_test = data['Sentences'][5000:6000] # Change the indices to select the desired number of test pairs y_train = data['Labels'][:5000] y_test = data['Labels'][5000:6000] # Change the indices to select the desired number of test pairsAfter making this change, the test will be performed on 1000 pairs instead of the original test set size.
- User
Split data into train and test sets
X_train = data['Sentences'][:5000] X_test = data['Sentences'][5000:6000] y_train = data['Labels'][:5000] y_test = data['Labels'][5000:6000]
the test here is the first 1000 i need the last 1000
- Assistant
To modify the code to use the last 1000 pairs for testing instead of the first 1000 pairs, you can update the following lines of code:
# Split data into train and test sets X_train = data['Sentences'][:5000] X_test = data['Sentences'][-1000:] # Change the indices to select the last 1000 test pairs y_train = data['Labels'][:5000] y_test = data['Labels'][-1000:] # Change the indices to select the last 1000 test pairsAfter making this change, the test will be performed on the last 1000 pairs instead of the first 1000 pairs.
- User
Load Quora dataset
quora_data = pd.read_csv('questions.csv', nrows=6000)
i want to take the first 6000 row from the dataset
- Assistant
To take the first 6000 rows from the dataset, you can update the following line of code:
quora_data = pd.read_csv('questions.csv', nrows=6000)By setting
nrows=6000, thepd.read_csv()function will only read the first 6000 rows from the dataset. - User
train_data = quora_data[:5000] this for first 5000 or last 5000
- Assistant
The line
train_data = quora_data[:5000]will select the first 5000 rows from the dataset.If you want to select the last 5000 rows instead, you can use
train_data = quora_data[-5000:]. Using a negative index-5000will select the last 5000 rows of the dataset. - User
test_data = quora_data[-1000:]
and this first 1000 or last 1000
- Assistant
The line
test_data = quora_data[-1000:]will select the last 1000 rows from the dataset.If you want to select the first 1000 rows instead, you can use
test_data = quora_data[:1000]. Using[:1000]will select the first 1000 rows of the dataset.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.