<jupyter_start><jupyter_text>This is my notebook on Transformers sentiment analysis in English<jupyter_code>from transformers import pipeline
classifier = pipeline('sentiment-analysis')
classifier('We are very happy to show you the 🤗 Transformers library.')
results = classifier(["We are very happy to show you the 🤗 Transformers library.", "We hope you don't hate it."])
for result in results:
    print(f"label: {result['label']}, with score: {round(result['score'], 4)}")
classifier = pipeline('sentiment-analysis', model="nlpaued/bert-base-greek-uncased-v1")
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
classifier = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)<jupyter_output>Downloading: 100%|██████████| 953/953 [00:00<?, ?B/s] 
Downloading: 100%|██████████| 669M/669M [01:52<00:00, 5.95MB/s]
Downloading: 100%|██████████| 872k/872k [00:01<00:00, 632kB/s]
Downloading: 100%|██████████| 112/112 [00:00<?, ?B/s] 
Downloading: 100%|██████████| 39.0/39.0 [00:00<00:00, 4.88kB/s]<jupyter_text>Parenthesis to check Greek Bert as it was published from NLP AUEB<jupyter_code>import unicodedata

def strip_accents_and_lowercase(s):
   return ''.join(c for c in unicodedata.normalize('NFD', s)
                  if unicodedata.category(c) != 'Mn').lower()

accented_string = "Αυτή είναι η Ελληνική έκδοση του BERT."
unaccented_string = strip_accents_and_lowercase(accented_string)

print(unaccented_string) # αυτη ειναι η ελληνικη εκδοση του bert.
from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
model = AutoModel.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")

from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
pt_model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
import torch
from transformers import *

# Load model and tokenizer
tokenizer_greek = AutoTokenizer.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')
lm_model_greek = AutoModelWithLMHead.from_pretrained('nlpaueb/bert-base-greek-uncased-v1')

# ================ EXAMPLE 1 ================
text_1 = 'O ποιητής έγραψε ένα [MASK] .'
# EN: 'The poet wrote a [MASK].'
input_ids = tokenizer_greek.encode(text_1)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
# ['[CLS]', 'o', 'ποιητης', 'εγραψε', 'ενα', '[MASK]', '.', '[SEP]']
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 5].max(0)[1].item()))
# the most plausible prediction for [MASK] is "song"

# ================ EXAMPLE 2 ================
text_2 = 'Είναι ένας [MASK] άνθρωπος.'
# EN: 'He is a [MASK] person.'
input_ids = tokenizer_greek.encode(text_1)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
# ['[CLS]', 'ειναι', 'ενας', '[MASK]', 'ανθρωπος', '.', '[SEP]']
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 3].max(0)[1].item()))
# the most plausible prediction for [MASK] is "good"

# ================ EXAMPLE 3 ================
text_3 = 'Είναι ένας [MASK] άνθρωπος και κάνει συχνά [MASK].'
# EN: 'He is a [MASK] person he does frequently [MASK].'
input_ids = tokenizer_greek.encode(text_3)
print(tokenizer_greek.convert_ids_to_tokens(input_ids))
# ['[CLS]', 'ειναι', 'ενας', '[MASK]', 'ανθρωπος', 'και', 'κανει', 'συχνα', '[MASK]', '.', '[SEP]']
outputs = lm_model_greek(torch.tensor([input_ids]))[0]
print(tokenizer_greek.convert_ids_to_tokens(outputs[0, 8].max(0)[1].item()))
# the most plausible prediction for the second [MASK] is "trips"<jupyter_output>C:\Users\nickr\anaconda3\lib\site-packages\transformers\modeling_auto.py:781: FutureWarning: The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use `AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and `AutoModelForSeq2SeqLM` for encoder-decoder models.
  warnings.warn(
Some weights of the model checkpoint at nlpaueb/bert-base-greek-uncased-v1 were not used when initializing BertForMaskedLM: ['cls.seq_relationship.weight', 'cls.seq_relationship.bias']
- This IS expected if you are initializing BertForMaskedLM from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPretraining model).
- This IS NOT expected if you are initializing BertForMaskedLM from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassifi[...]<jupyter_text>Back to English instructions<jupyter_code>from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = "distilbert-base-uncased-finetuned-sst-2-english"
pt_model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
inputs = tokenizer("We are very happy to show you the 🤗 Transformers library.")    
$x_{1} + x_{2} + \cdots + x_{n}$
from nltk import ngrams

sentence = 'this is a foo bar sentences and i want to ngramize it'

n = 2
sixgrams = ngrams(sentence.split(), n)

for grams in sixgrams:
  print (grams)

from GoogleNews import GoogleNews

googlenews = GoogleNews()
googlenews = GoogleNews(period ='7d')
googlenews.search('Greece')
result=googlenews.result()
for x in result:
    print("_"*50)
    print("Title--",x['title'])
    print("Date/Time--",x['date'])
    print("description--",x['desc'])
    print("Link--",x['link'])
    write.csv()<jupyter_output>__________________________________________________
Title-- Spain, Greece and US holidays 'optimistically' boosted ahead ...
Date/Time-- 39 mins ago
description-- SPAIN, Greece and the USA all did not make the Government's travel "green list" on Friday. However, with the list set to be reviewed every three weeks, it seems ...
Link-- https://www.express.co.uk/travel/articles/1433791/spain-greece-us-holidays-green-list-travel-bookings-review
__________________________________________________
Title-- High Bar for Proof Limits Interest for Greek Citizenship Test
Date/Time-- 53 mins ago
description-- ... in Greece for at least several years. “Interest is already great for the exams scheduled to take place in September,” they added without explaining why it wasn't ...
Link-- https://www.thenationalherald.com/archive_general_news_greece/arthro/high_bar_for_proof_limits_interest_for_greek_citizenship_test-2397515/
__________________________________________________
Title-- Woman in Athens Acid A[...]
{'fraction_non_alphanumeric': 0.1385908959118585, 'fraction_numerical': 0.0214554943461873, 'mean_word_length': 6.4342672413793105, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '251277', 'license': 'MIT', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2270, 'n_words': 571, 'path': 'Transformers Sentiment Analysis.ipynb', 'repo_name': 'nickrystallis/Sentiment-Analysis-Greek-Bert', 'size': '6898'}