{
  "slug": "NLP-tutorial-cf3f48ed14fb",
  "title": "NLP tutorial",
  "subtitle": "Sentiment Analysis",
  "excerpt": "Sentiment Analysis",
  "date": "2024-01-25",
  "tags": [
    "Machine Learning"
  ],
  "readingTime": "3 min",
  "url": "https://medium.com/@mobinshaterian/nlp-tutorial-cf3f48ed14fb",
  "hero": "https://cdn-images-1.medium.com/max/800/1*TQRoCi97MUqU0brxu09z0Q.png",
  "content": [
    {
      "type": "paragraph",
      "html": "Sentiment Analysis"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Multi-class Text classification with GPT 3.5"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "10 Leading Language Models For NLP In 2022"
    },
    {
      "type": "list",
      "ordered": true,
      "items": [
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-1\" target=\"_blank\" rel=\"noreferrer noopener\">BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</a>",
        "GPT2: <a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-2\" target=\"_blank\" rel=\"noreferrer noopener\">Language Models Are Unsupervised Multitask Learners</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-3\" target=\"_blank\" rel=\"noreferrer noopener\">XLNet: Generalized Autoregressive Pretraining for Language Understanding</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-4\" target=\"_blank\" rel=\"noreferrer noopener\">RoBERTa: A Robustly Optimized BERT Pretraining Approach</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-5\" target=\"_blank\" rel=\"noreferrer noopener\">ALBERT: A Lite BERT for Self-supervised Learning of Language Representations</a>",
        "T5: <a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-6\" target=\"_blank\" rel=\"noreferrer noopener\">Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer</a>",
        "GPT3: <a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-7\" target=\"_blank\" rel=\"noreferrer noopener\">Language Models Are Few-Shot Learners</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-8\" target=\"_blank\" rel=\"noreferrer noopener\">ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-9\" target=\"_blank\" rel=\"noreferrer noopener\">DeBERTa: Decoding-enhanced BERT with Disentangled Attention</a>",
        "<a href=\"https://www.topbots.com/leading-nlp-language-models-2020/#language-models-2022-10\" target=\"_blank\" rel=\"noreferrer noopener\">PaLM: Scaling Language Modeling with Pathways</a>"
      ]
    },
    {
      "type": "heading",
      "level": 2,
      "text": "New AI classifier for indicating AI-written text"
    },
    {
      "type": "paragraph",
      "html": "We’re launching a classifier trained to distinguish between AI-written and human-written text."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "limitation"
    },
    {
      "type": "list",
      "ordered": true,
      "items": [
        "The classifier is very unreliable on short texts (below 1,000 characters). Even longer texts are sometimes incorrectly labeled by the classifier.",
        "Sometimes human-written text will be incorrectly but confidently labeled as AI-written by our classifier.",
        "We recommend using the classifier only for English text. It performs significantly worse in other languages and it is unreliable on code.",
        "Very predictable text cannot be reliably identified. For example, it is impossible to predict whether AI or humans wrote a list of the first 1,000 prime numbers because the correct answer is always the same.",
        "AI-written text can be edited to evade the classifier. Classifiers like ours can be updated and retrained based on successful attacks, but it is unclear whether detection has long-term advantages.",
        "Classifiers based on neural networks are known to need to be better calibrated outside of their training data. For inputs that are very different from the text in our training set, the classifier is sometimes extremely confident in a wrong prediction."
      ]
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Tagging and multi-class classification"
    },
    {
      "type": "embed",
      "provider": "youtube",
      "url": "https://www.youtube.com/embed/a8hMgIcUEnE?feature=oembed"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Fine-tuning"
    },
    {
      "type": "paragraph",
      "html": "Learn how to customize a model for your application."
    },
    {
      "type": "paragraph",
      "html": "<a href=\"https://platform.openai.com/docs/guides/fine-tuning\" target=\"_blank\" rel=\"noreferrer noopener\">https://platform.openai.com/docs/guides/fine-tuning</a>"
    },
    {
      "type": "paragraph",
      "html": "<a href=\"https://www.youtube.com/watch?v=ahnGLM-RC1Y\" target=\"_blank\" rel=\"noreferrer noopener\">https://www.youtube.com/watch?v=ahnGLM-RC1Y</a>"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*BkwoKgBYbxYnUrGg3YV6uw.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 937,
      "height": 497
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*6GGx56fUGdChD4EA4ayc9A.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 752,
      "height": 378
    },
    {
      "type": "paragraph",
      "html": "RAG retrieval augmented generation"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*R_dNDZMqywRUuoUN-qq9Jg.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 1509,
      "height": 697
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*Ll2CFv93wy-2WVR2idzO4Q.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 1520,
      "height": 739
    },
    {
      "type": "paragraph",
      "html": "RAG"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*uQC_hhGXbUsCG5UHdbDTmg.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 1527,
      "height": 744
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*xbfyprotDuIerXV9ukLWag.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 1069,
      "height": 515
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Term Frequency Text Summarization"
    },
    {
      "type": "paragraph",
      "html": "Remove stop words"
    },
    {
      "type": "code",
      "lang": "python",
      "code": "text =\n\" Sometimes to understand a word's meaning you need more than a definition; you need to see the word used in a sentence. At YourDictionary, we give you the tools to learn what a word means and how to use it correctly. With this sentence maker, simply type a word in the search bar and see a variety of sentences with that word used in its different ways. Our sentence generator can provide more context and relevance, ensuring you use a word the right way.\"\nimport retext = re.sub(' +',' ', text)\ntext = text.replace('\\n', ' ')\ntext = text.replace('\\t', ' ')\ntext = text.replace('\\r', ' ')\ntext = text.replace('\\\"', ' ')\ntext = text.replace('\\'', ' ')\ntext = text.lower()\npattern = r'we[\\'\\']re'\nreplacement = 'we are'\ntext = re.sub(pattern,replacement,text)\npattern = r'we[\\'\\']ll'\nreplacement = 'we will'\ntext = re.sub(pattern,replacement,text) from bs4 import BeautifulSoup as bs4\nimport requests\nimport nltk\nfrom nltk.tokenize import RegexpTokenizer\nimport heapq\nimport re\nfrom wordcloud import WordCloud, STOPWORDS\nimport matplotlib.pyplot as plttokenizer = RegexpTokenizer('\\w+')\nwords = tokenizer.tokenize(text)\nsentences = nltk.sent_tokenize(text)\nfrom nltk.corpus import stopwords\nfrom nltk.tokenize import word_tokenize stop_words = set(stopwords.words('english')) word_tokens = word_tokenize(text)# converts the words in word_tokens to lowercase and then checks whether #they are present in stop_words or notfiltered_sentence = [w for w in word_tokens if not w.lower() in stop_words]#with no lowercase conversionfiltered_sentence = [] for w in word_tokens:    if w not in stop_words:        filtered_sentence.append(w) words = filtered_sentencefrequency = nltk.FreqDist(words)\nmax_frequency = max(frequency.values())\nfor word in frequency.keys():    frequency[word] = frequency[word]/max_frequencyviz_words = [x for x in words if x not in nltk.corpus.stopwords.words('english')]\nviz_words = [x for x in viz_words if x not in ['thing', 'min', 'really', 'wanted', 'way', 'want', 'going']]\nviz_frequency = nltk.FreqDist(viz_words)\ncloud = heapq.nlargest(40, viz_frequency, key=viz_frequency.get)\ndef plot_cloud(wordcloud):    plt.figure(figsize=(20, 15))    plt.imshow(wordcloud)     plt.axis(\"off\")    plt.savefig('wordcloud.png');wordcloud = WordCloud(width=3000, height=2000, random_state=1,                       background_color='#f7f0ee', colormap='binary_r',                       collocations=False, stopwords=STOPWORDS).generate(' '.join(cloud))plot_cloud(wordcloud)"
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*TQRoCi97MUqU0brxu09z0Q.png",
      "alt": "NLP tutorial",
      "caption": "",
      "width": 783,
      "height": 528
    },
    {
      "type": "paragraph",
      "html": "Visit us at <a href=\"https://www.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>DataDrivenInvestor.com</em></a>"
    },
    {
      "type": "paragraph",
      "html": "Subscribe to DDIntel <a href=\"https://www.ddintel.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>here</em></a>."
    },
    {
      "type": "paragraph",
      "html": "Have a unique story to share? Submit to DDIntel <a href=\"https://datadriveninvestor.com/ddintelsubmission\" target=\"_blank\" rel=\"noreferrer noopener\"><em>here</em></a>."
    },
    {
      "type": "paragraph",
      "html": "Join our creator ecosystem <a href=\"https://join.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>here</em></a>."
    },
    {
      "type": "paragraph",
      "html": "<a href=\"https://ddintel.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>DDIntel</em> </a>captures the more notable pieces from our <a href=\"https://www.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>main site</em></a> and our popular <a href=\"https://medium.datadriveninvestor.com/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>DDI Medium publication</em></a>. Check us out for more insightful work from our community."
    },
    {
      "type": "paragraph",
      "html": "DDI Official Telegram Channel: <a href=\"https://t.me/+tafUp6ecEys4YjQ1\" target=\"_blank\" rel=\"noreferrer noopener\">https://t.me/+tafUp6ecEys4YjQ1</a>"
    },
    {
      "type": "paragraph",
      "html": "Follow us on <a href=\"https://www.linkedin.com/company/data-driven-investor\" target=\"_blank\" rel=\"noreferrer noopener\"><em>LinkedIn</em></a>, <a href=\"https://twitter.com/@DDInvestorHQ\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Twitter</em></a>, <a href=\"https://www.youtube.com/c/datadriveninvestor\" target=\"_blank\" rel=\"noreferrer noopener\"><em>YouTube</em></a>, and <a href=\"https://www.facebook.com/datadriveninvestor\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Facebook</em></a>."
    }
  ]
}
