<jupyter_start><jupyter_text><jupyter_code>!cp /content/drive/MyDrive/twitter_dashboard/bert-fa-base-uncased-sentiment-twitter/vocab.txt /parsbert-fa-sentiment-twitter
!mv vocab.txt /parsbert-fa-sentiment-twitter
!cp /content/drive/MyDrive/twitter_dashboard/bert-fa-base-uncased-sentiment-twitter/vocab.txt .
!cat /content/vocab.txt >> /content/parsbert-fa-sentiment-twitter/vocab.txt
!touch /content/parsbert-fa-sentiment-twitter/vocab.txt
!ls
!bash
!ls -sh /content/drive/MyDrive/twitter_dashboard/bert-fa-base-uncased-sentiment-twitter/
from transformers import BertConfig, BertTokenizer
from transformers import TFBertModel, TFBertForSequenceClassification
from transformers import glue_convert_examples_to_features

import tensorflow as tf

inputs = tokenizer("افتضاح بود")
tf_batch = tokenizer(
    ["خیلی خوب بود", "افتضاح بود"],
    padding=True,
    truncation=True,
    max_length=128,
    return_tensors="tf"
)
for key, value in tf_batch.items():
...     print(f"{key}: {value.numpy().tolist()}")
tf_outputs = model(tf_batch)
tf_outputs = model(tf_batch, labels = tf.constant([1, 0]))
tf_predictions = tf.nn.softmax(tf_outputs[1],axis=-1)
tf_predictions

import numpy as np
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
#loading model
tokenizer = AutoTokenizer.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
  
model = TFAutoModelForSequenceClassification.from_pretrained("nimaafshar/parsbert-fa-sentiment-twitter")
classes = ["negative","neutral","positive"]

#using model
sequences = [".غذا خیلی افتضاح بود متاسفم برای مدیریت رستورن خیلی بد بود.",
 "خیلی خوشمزده و عالی بود عالی",
"می‌تونم اسمتونو بپرسم؟"
]

for sequence in sequences:
  inputs = tokenizer(sequence, return_tensors="tf")
  classification_logits = model(inputs)[0]
  results = tf.nn.softmax(classification_logits, axis=1).numpy()[0]
  print(classes[np.argmax(results)])
  percentages = np.around(results*100)
  print(percentages)
  

# # Should be paraphrase
# for i in range(len(classes)):
#     print(f"{classes[i]}: {int(round(paraphrase_results[i] * 100))}%")

# # Should not be paraphrase
# for i in range(len(classes)):
#     print(f"{classes[i]}: {int(round(not_paraphrase_results[i] * 100))}%")
#complete code
!cat << /content/drive/MyDrive/twitter_dashboard/bert-fa-base-uncased-sentiment-twitter/vocab.txt
!git clone https://huggingface.co/HooshvareLab/bert-fa-base-uncased-sentiment-digikala
!cp bert-fa-base-uncased-sentiment-digikala/vocab.txt /content/parsbert-fa-sentiment-twitter/vocab.txt
!head /content/parsbert-fa-sentiment-twitter/vocab.txt<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13273001508295626, 'fraction_numerical': 0.007164404223227752, 'mean_word_length': 5.377403846153846, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '344657', 'license': 'MIT', 'n_tokens_mistral': 1058, 'n_tokens_neox': 998, 'n_words': 156, 'path': 'notebooks/feeding-data-to-bert-model-and-deployment.ipynb', 'repo_name': 'AUT-Twitter-Analytics/Streamlit-Dashboard', 'size': '2652'}