<jupyter_start><jupyter_text>Integrating models with 0.5 as weights   Load Images Model and make the prediction:<jupyter_code>from models.Images_classifier import Show_pred_BIT
import tensorflow as tf
import tensorflow_hub as hub
# Load saved model
saved_module = hub.KerasLayer("BiT1011/", trainable=True)
def get_pred_img(file_path):
    L=Show_pred_BIT.predict_image_logit(saved_module,correct_label=0, file_path=file_path)
    if len(L.shape) > 1:
            L = tf.reshape(L, [-1])
    MAX_PREDS = 2
    LABELS_N=["Depressed","Not Depressed"]
    classes = []
    scores = []
    logits_max = np.max(L)
    softmax_denominator = np.sum(np.exp(L - logits_max))
    for index, j in enumerate(np.argsort(L)[-MAX_PREDS::][::-1]):
        score = 1.0/(1.0 + np.exp(-L[j]))
        classes.append(LABELS_N[j])
        scores.append(np.exp(L[j] - logits_max)/softmax_denominator)
    if classes[0]=="Depressed":
        pred_p=scores[0]
        pred_n=scores[1]
    else:
        pred_p=scores[1]
        pred_n=scores[0]
    return(pred_n,pred_p)
D,N=get_pred_img("data/Data_for_multimodal_test/1.jpg")<jupyter_output><empty_output><jupyter_text>Load Text Model and make the prediction:<jupyter_code>classes_index = {
    1 : "Depressed",
    0 : "Not depressed"
}
from tensorflow import keras
import pickle
model = keras.models.load_model('Exp_prep_10k_32ep/model_BiGloVe.h5')
# loading
with open('Exp_prep_10k_32ep/tokenizer_BiGlove.pickle', 'rb') as handle:
    tokenizer = pickle.load(handle)
test_texts=["So been drawing a lot of stuff recently that I can’t share here, but I can share doodles of my WOL from #ff14  Kade. Who has a crush on @Behaxeltzi ‘s boy and his sister Rheila. pic.twitter.com/RrridlgIHJ",
           " Given the #Corona lock-in's, I decided to put up one of my #criticalrole linearts that people can download for free to colour! If you do please do feel free to tag me in any posts online.  I do sell and plan to release more large scale packs at  https://gumroad.com/lissyraine  pic.twitter.com/If5UauncoL"
           ,
            "NOT THE SKINNY ASS WRIST, VEINS AND THE HANDCUFF BRACELET😭😭 DONRY HOURS pic.twitter.com/9DGuLfh6A4"
           ,"😍Found this on a client's bookshelf. Of course I read what I could in the short time I was there. Even though I already read #AliceInWonderland before😁 #aiw #Reading #books #storytime #booklover pic.twitter.com/cKpk76ecq2",
            "Found a gigantic #connect4 game during our #homeschool field trip. We couldn't resist😁 #homeschooling #boardgame pic.twitter.com/J8EkvYQfVC",
            "#Nanny #nannylife #Reading #book #BookRecommendations #Halloween #abcs #alphabet pic.twitter.com/BNcMmW9eM9  " 
           ]
Labels_profile=["Depressed","Depressed","Depressed","Not Depressed","Not Depressed","Not Depressed"]

from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
import numpy as np
def predict_tweet_BiGlove(text_to_predict):
    test_sequence = tokenizer.texts_to_sequences([text_to_predict])
    test_data = pad_sequences(test_sequence, maxlen=197)
    predictions = model.predict(test_data)
    prediction = np.argmax(predictions)
    pred_n=predictions[0][0]
    pred_p=predictions[0][1]
    return(pred_n,pred_p)
pred1 , pred2 =predict_tweet_BiGlove(test_texts[1])
pred1, pred2<jupyter_output><empty_output><jupyter_text>Multimodal:This approach supposes that a social network user posts an image and a photo to express himself giving the same importance to both.<jupyter_code>from matplotlib.pyplot import imshow
import matplotlib.pyplot as plt
from PIL import Image
import cv2
%matplotlib inline
def multimodal_pred_post(file_path, text_to_predict,label):
    # Calculate prob with a multimodal aspect
    pred_text_N, pred_text_P=predict_tweet_BiGlove(text_to_predict)
    pred_Image_N, pred_Image_P=get_pred_img(file_path)
    Pred_multimodal_N=0.5*pred_text_N+0.5*pred_Image_N
    Pred_multimodal_P=0.5*pred_text_P+0.5*pred_Image_P
    # print both img and status 
    print("The person who posted this is",label)
    print()
    print(text_to_predict)
    img = cv2.imread(file_path)
    plt.imshow(img)
    plt.show()
    print()
    print("The Text prediction is ",str(round(pred_text_P*100,3)),"% Depressed and",str(round(pred_text_N*100,3)),"% Not Depressed ")
    print("The Image prediction is ",str(round(pred_Image_P*100,3)),"% Depressed and",str(round(pred_Image_N*100,3)),"% Not Depressed ")
    print("The Multimodal prediction is ",str(round(Pred_multimodal_P*100,3)),"% Depressed and",str(round(Pred_multimodal_N*100,3)),"% Not Depressed ")
    print()
for i in range(6):
    print(" *********************************  Post number ",str(i+1),"  ****************************")
    multimodal_pred_post("data/Data_for_multimodal_test/"+str(i+1)+".jpg",test_texts[i],Labels_profile[i])<jupyter_output>*********************************  Post number  1   ****************************
The person who posted this is Depressed

So been drawing a lot of stuff recently that I can’t share here, but I can share doodles of my WOL from #ff14  Kade. Who has a crush on @Behaxeltzi ‘s boy and his sister Rheila. pic.twitter.com/RrridlgIHJ
{'fraction_non_alphanumeric': 0.12550451662502402, 'fraction_numerical': 0.01864309052469729, 'mean_word_length': 4.737596471885336, 'pattern_counts': {'":': 1, '<': 12, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '172177', 'license': 'Apache-2.0', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1804, 'n_words': 445, 'path': 'Integrating_Models.ipynb', 'repo_name': 'BouzidiImen/Social_media_Prediction_depression', 'size': '5203'}