<jupyter_start><jupyter_text>Fake NewsCopyright 2022, <NAME> Notebook resources:[Hugging Face](https://huggingface.co)[The Allen Institute for AI](https://allennlp.org/)Some of Allen NLP resources come from Hugging Face  Fake News from an emotional perspective Allen NLP Sentiment Analysis with RoBERTa-large<jupyter_code>!pip install allennlp==1.0.0 allennlp-models==1.0.0<jupyter_output>Collecting allennlp==1.0.0
  Downloading allennlp-1.0.0-py3-none-any.whl (473 kB)
[?25l
[K     |▊                               | 10 kB 27.9 MB/s eta 0:00:01
[K     |█▍                              | 20 kB 30.4 MB/s eta 0:00:01
[K     |██                              | 30 kB 12.5 MB/s eta 0:00:01
[K     |██▊                             | 40 kB 9.2 MB/s eta 0:00:01
[K     |███▌                            | 51 kB 5.4 MB/s eta 0:00:01
[K     |████▏                           | 61 kB 5.3 MB/s eta 0:00:01
[K     |████▉                           | 71 kB 5.5 MB/s eta 0:00:01
[K     |█████▌                          | 81 kB 6.1 MB/s eta 0:00:01
[K     |██████▎                         | 92 kB 6.2 MB/s eta 0:00:01
[K     |███████                         | 102 kB 5.1 MB/s eta 0:00:01
[K     |███████▋                        | 112 kB 5.1 MB/s eta 0:00:01
[K     |████████▎                       | 122 kB 5.1 MB/s eta 0:00:01
[K     |█████████                       | 133 kB 5.1 MB/s eta 0:[...]<jupyter_text>Running the predictor<jupyter_code>!echo '{"sentence":"Climate change is bogus. It’s a plot by the liberals to take the economy down."}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -
!echo '{"sentence":"I am a Republican and think that climate change consciousness is a great thing!"}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -<jupyter_output>2022-01-17 20:41:56,641 - INFO - transformers.file_utils - PyTorch version 1.5.1 available.
2022-01-17 20:42:01,497 - INFO - transformers.file_utils - TensorFlow version 2.7.0 available.
2022-01-17 20:42:02,864 - INFO - allennlp.common.file_utils - checking cache for https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz at /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac
2022-01-17 20:42:02,864 - INFO - allennlp.common.file_utils - waiting to acquire lock on /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac
2022-01-17 20:42:02,865 - INFO - filelock - Lock 140268424395344 acquired on /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac.lock
2022-01-17 2[...]<jupyter_text>GUN CONTROL<jupyter_code>!echo '{"sentence":"I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits."}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -
!echo '{"sentence":"I have heard gunshots all my life in my neighborhood, have lost many friends, and am afraid to go out at night."}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz -<jupyter_output>2022-01-17 20:43:27,333 - INFO - transformers.file_utils - PyTorch version 1.5.1 available.
2022-01-17 20:43:30,314 - INFO - transformers.file_utils - TensorFlow version 2.7.0 available.
2022-01-17 20:43:31,176 - INFO - allennlp.common.file_utils - checking cache for https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.06.08.tar.gz at /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac
2022-01-17 20:43:31,176 - INFO - allennlp.common.file_utils - waiting to acquire lock on /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac
2022-01-17 20:43:31,177 - INFO - filelock - Lock 139717084795408 acquired on /root/.allennlp/cache/8255466347f7b3a13b6bf71883dca4a02eefc30ce15004b8b41ba231b0e3de6d.f4aa9e5021ce7bf3c17488c8924b4aad654883a2f0b65528127695344bb741ac.lock
2022-01-17 2[...]<jupyter_text>NER with Hugging Face<jupyter_code>!pip install -q transformers
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSequenceClassification,AutoModel
nlp_token_class = pipeline('ner')
nlp_token_class('I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits.')
nlp_token_class = pipeline('ner')
nlp_token_class('I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits.')
nlp_token_class.model.config<jupyter_output><empty_output><jupyter_text>SRL with AllenNLP<jupyter_code>!echo '{"sentence": "I have had rifles and guns for years and never had a problem. I raised my kids right so they have guns too and never hurt anything except rabbits."}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.03.24.tar.gz -

!echo '{"sentence": "I have heard gunshots all my life in my neighborhood, have lost many friends, and am afraid to go out at night."}' | \
allennlp predict https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.03.24.tar.gz -<jupyter_output>2022-01-17 20:46:06,468 - INFO - transformers.file_utils - PyTorch version 1.5.1 available.
2022-01-17 20:46:09,647 - INFO - transformers.file_utils - TensorFlow version 2.7.0 available.
2022-01-17 20:46:10,462 - INFO - allennlp.common.file_utils - checking cache for https://storage.googleapis.com/allennlp-public-models/bert-base-srl-2020.03.24.tar.gz at /root/.allennlp/cache/e20d5b792a8d456a1a61da245d1856d4b7778efe69ac3c30759af61940aa0f42.f72523a9682cb1f5ad3ecf834075fe53a1c25a6bcbf4b40c11e13b7f426a4724
2022-01-17 20:46:10,462 - INFO - allennlp.common.file_utils - waiting to acquire lock on /root/.allennlp/cache/e20d5b792a8d456a1a61da245d1856d4b7778efe69ac3c30759af61940aa0f42.f72523a9682cb1f5ad3ecf834075fe53a1c25a6bcbf4b40c11e13b7f426a4724
2022-01-17 20:46:10,463 - INFO - filelock - Lock 140293729754576 acquired on /root/.allennlp/cache/e20d5b792a8d456a1a61da245d1856d4b7778efe69ac3c30759af61940aa0f42.f72523a9682cb1f5ad3ecf834075fe53a1c25a6bcbf4b40c11e13b7f426a4724.lock
2022-01-17 20:46[...]
{'fraction_non_alphanumeric': 0.112481426448737, 'fraction_numerical': 0.1922734026745914, 'mean_word_length': 3.8634393063583814, 'pattern_counts': {'":': 6, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '594427', 'license': 'MIT', 'n_tokens_mistral': 3410, 'n_tokens_neox': 2648, 'n_words': 509, 'path': 'Chapter13/Fake_News.ipynb', 'repo_name': 'sparsh-ai/Transformers-for-NLP-2nd-Edition', 'size': '6737'}