<jupyter_start><jupyter_text>ML models  SGD<jupyter_code># Load the model from the file
SGD_from_joblib = joblib.load('model/ml/SGD_tfidf_vectorizer.pkl')
# tfidf vectorizer transformation 
tfidf_obj = joblib.load('model/vect/_tfidf_vect_labelled.pkl')
print(type(tfidf_obj))

X_test = tfidf_obj.transform(X_test.astype('U'))

# Calculate the Score 
score = SGD_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 66.78 %<jupyter_text>Random Forest<jupyter_code># Load the model from the file
RF_from_joblib = joblib.load('model/ml/random_forest_tfidf_vectorizer.pkl')
print(type(RF_from_joblib))
# Calculate the Score 
score = RF_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 67.56 %<jupyter_text>SVM<jupyter_code># Load the model from the file
SVM_from_joblib = joblib.load('model/ml/svm_tfidf_vectorizer.pkl')
# Calculate the Score 
score = SVM_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 67.72 %<jupyter_text>Naivye Bayes<jupyter_code># Load the model from the file
NB_from_joblib = joblib.load('model/ml/naive_bayes_tfidf_vectorizer.pkl')
# Calculate the Score 
score = NB_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 66.50 %<jupyter_text>KNN<jupyter_code># Load the model from the file
KNN_from_joblib = joblib.load('model/ml/KNeighborsClassifier_tfidf_vectorizer.pkl')
# Calculate the Score 
score = KNN_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 61.50 %<jupyter_text>Logistic Regression<jupyter_code># Load the model from the file
LR_from_joblib = joblib.load('model/ml/logistic_regression_tfidf_vectorizer.pkl')
# Calculate the Score 
score = LR_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 68.22 %<jupyter_text>Decision Tree<jupyter_code># Load the model from the file
DT_from_joblib = joblib.load('model/ml/DecisionTreeClassifier_tfidf_vectorizer.pkl')
# Calculate the Score 
score = DT_from_joblib.score(X_test, y_test)  
# Print the Score
print("Test Accuracy score: {0:.2f} %".format(100 * score))<jupyter_output>Test Accuracy score: 62.06 %<jupyter_text>Deep learning models<jupyter_code># Load the model from the file
#lstm_from_joblib = joblib.load('lstm_best_model.h5')

import gensim.downloader as api
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras import backend as K
import tensorflow as tf
import keras
max_words = 5000
max_len = 200

n_epochs = 8
from keras import backend as kb 



tokenizer = joblib.load('model/vect/dl_tokenizer.pkl')
print(type(tokenizer))


sequences = tokenizer.texts_to_sequences(tweets_label_test_df["clean_data"].values.astype('U'))
tweets = pad_sequences(sequences, maxlen=max_len)
print(tweets)

labels = tf.keras.utils.to_categorical(tweets_label_test_df["label"], dtype="float32")

model = keras.models.load_model('model/dl/lstm_best_model.h5')
try:
    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
    tf.config.experimental_connect_to_cluster(tpu)
    tf.tpu.experimental.initialize_tpu_system(tpu)
    strategy = tf.distribute.experimental.TPUStrategy(tpu)
    
except:
    strategy = tf.distribute.get_strategy()
    
print('Number of replicas in sync: ', strategy.num_replicas_in_sync)
#! rm -rf ~/.nv
test_loss, test_acc = model.evaluate(tweets, labels, verbose=2)
print('Model accuracy: ',test_acc)
bilstm_model = keras.models.load_model('model/dl/bi_lstm_best_model.h5')
test_loss, test_acc = bilstm_model.evaluate(tweets, labels, verbose=2)
print('Model accuracy: ',test_acc)
gru_model = keras.models.load_model('model/dl/gru_best_model.h5')
test_loss, test_acc = gru_model.evaluate(tweets, labels, verbose=2)
print('Model accuracy: ',test_acc)
import tensorflow_hub as hub
ct_bert_saved_model = tf.keras.models.load_model(('model/bert/ct_bert_model.h5'),custom_objects={'KerasLayer':hub.KerasLayer})

from  official.nlp.bert import tokenization
%%time
 
bert_layer = hub.KerasLayer("https://tfhub.dev/digitalepidemiologylab/covid-twitter-bert/2", trainable=True)
vocab_file = bert_layer.resolved_object.vocab_file.asset_path.numpy()
do_lower_case = bert_layer.resolved_object.do_lower_case.numpy()
tokenizer = tokenization.FullTokenizer(vocab_file, do_lower_case)
def ct_bert_encode(texts, tokenizer, max_len=512):
    all_tokens = []
    all_masks = []
    all_segments = []
    
    for text in texts:
        text = tokenizer.tokenize(text)
            
        text = text[:max_len-2]
        input_sequence = ["[CLS]"] + text + ["[SEP]"]
        pad_len = max_len - len(input_sequence)
        
        tokens = tokenizer.convert_tokens_to_ids(input_sequence)
        tokens += [0] * pad_len
        pad_masks = [1] * len(input_sequence) + [0] * pad_len
        segment_ids = [0] * max_len
        
        all_tokens.append(tokens)
        all_masks.append(pad_masks)
        all_segments.append(segment_ids)
    
    return np.array(all_tokens), np.array(all_masks), np.array(all_segments)
texts = tweets_label_test_df["clean_data"].astype('U')
target = labels

tweets = ct_bert_encode(texts, tokenizer, max_len=100)
test_loss, test_acc = ct_bert_saved_model.evaluate(tweets, labels, verbose=2)
print('Model accuracy: ',test_acc)<jupyter_output>57/57 - 640s - loss: 0.9861 - accuracy: 0.6989
Model accuracy:  0.698888897895813
{'fraction_non_alphanumeric': 0.11726384364820847, 'fraction_numerical': 0.021772672724155666, 'mean_word_length': 5.690366972477064, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '138920', 'license': 'Apache-2.0', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2173, 'n_words': 399, 'path': 'predict_test_labelled_data/mode_prediction_with_labelled_data.ipynb', 'repo_name': 'reachrkr/covid19-vaccination-ssl', 'size': '5833'}