# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + [markdown] id="view-in-github" colab_type="text"
# <a href="https://colab.research.google.com/github/holps-7/NLP-weekly/blob/master/NLP_week3.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>

# + id="y1SHYM0ivKJN" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="42eb2292-0602-487d-d407-f1311f8fb204"
nltk.download('all')

# + id="s8lXyxJexaf1" colab_type="code" colab={}
import nltk

# + id="H1w9PeJKvTbQ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="a453bd0c-48f9-4145-b35a-443529cf4a51"
text = '''
A trained language model generates text. We can optionally pass it some text as input, which influences its output. 
The output is generated from what the model “learned” during its training period where it scanned vast amounts of text. 
Training is the process of exposing the model to lots of text. That process has been completed. All the experiments you see now 
are from that one trained model. It was estimated to cost 355 GPU years and cost $4.6m. The dataset of 300 billion tokens of text 
is used to generate training examples for the model. For example, these are three training examples generated from the one sentence at the top.
You can see how you can slide a window across all the text and make lots of examples.
'''

for text1 in text:
  sentences = nltk.sent_tokenize(text1)
  for sentence in sentences:
    words = nltk.word_tokenize(sentence)
    tagged = nltk.pos_tag(words)
    print(tagged)

# + id="8Y6EgPUtwQAZ" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 306} outputId="f807d80b-1d2b-424b-e071-5a96325d49f5"
from nltk.tokenize import TweetTokenizer
text = '''Wind and solar are the cheapest source of new power for two-thirds of the world's population.'''
twtk = TweetTokenizer()
twtk.tokenize(text)

# + id="eVGNrK2gyu9k" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 71} outputId="b6fe87e6-8247-434f-c452-e5010e9020d3"
from urllib import request
url = "http://www.gutenberg.org/files/2557/2557-0.txt"
resp = request.urlopen(url)
raw = resp.read().decode('utf8')
len(raw)
print(raw[:75])
from nltk.tokenize import word_tokenize
tokens = word_tokenize(raw)
print(tokens)

# + id="_mJJ2iXq2FYp" colab_type="code" colab={}
#A Python script to download all the tweets of a hashtag into a csv

import tweepy
import csv
import pandas as pd
####input your credentials here
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
#####United Airlines
# Open/Create a file to append data
csvFile = open('ua.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)

for tweet in tweepy.Cursor(api.search,q="#unitedAIRLINES",count=100,
                           lang="en",
                           since="2017-04-03").items():
    print (tweet.created_at, tweet.text)
    csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])

# + id="Gr6ebdcdztYL" colab_type="code" colab={"base_uri": "https://localhost:8080/", "height": 323} outputId="2a7beb14-5f82-49c5-d684-12afb2d2a019"
import nltk
f = open('tweets1.txt', 'r')
text = f.read()
text1 = text.split()
text2 = nltk.Text(text1)
text2.concordance('good')

# + id="vvjIS7k_3Kfq" colab_type="code" colab={}


StarcoderdataJupyterScriptsDedupFiltered