One very interesting task on the NLP fields is text generation.

There are very advanced techniques and a lot of research on it and even business based solely on it!

But how does it work?

[7.47min]
[I guarantee it's a much better read then doom scrolling!!!]

1/11🧵
Let's think: what a model would have to do to generate text?

The rationale is, as humans we form sentences by trying to create a sequence of words that makes sense.

The less random this sequence looks like, the better the output text is and closer to human like.

2/11🧵
Here is where ML can help.

A model should learn how to combine the words the best way possible.
The simplest way to teach this is: given a sentence, hide the last word and let the model try to guess it.

The loss function measures how good the model's guess is.

3/11🧵
This is what's called creating n-grams
You can do by word, by letter, phonemes, etc

en.wikipedia.org/wiki/N-gram

4/11🧵
To create your own dataset is just lot's of text that we know is written with proper grammar for our language. For example all Shakespeare writing

How about the model architecture?

5/11🧵
We need, as mentioned before, a text embedding.

We also need layers that understand sequences like Recurrent Neural Networks (RNN) or even better, LSTM (Long Short-Term Memory)

Here is a full example: tensorflow.org/tutorials/text…

6/11🧵
The Verse by Verse experiment shows how far this idea can go: sites.research.google/versebyverse/

The presented solution is much more complex but now you understand the basics!

7/11🧵
Text Generation is almost synonyms to OpenAI's GPT-3

I guess by now you've seen the amazing text that can be generated by just giving a beginning for the model to follow up

Code: github.com/openai/gpt-3
Paper: arxiv.org/abs/2005.14165

8/11🧵
Generating text is more than a technical challenge.
The results of a model can be used for good and there are already startups that are based on GPT-3!

theverge.com/2021/3/29/2235…

But it can also be used for not so noble ends.

9/11🧵
One interesting consequence of huge models that generate text is: These models are trained using the internet as source. The more these models generate text and this is published on sites, the more the model will use itself as training material later!
👀🤔

10/11🧵
Sorry for the long thread but this subject is fascinating for me!

And no, this thread wasn't automatically generated by ML…. or was it?

🤖🤔👀😱

11/11🧵

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Luiz GUStavo

Luiz GUStavo Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @gusthema

3 Apr
Today is my birthday!

As my gift to you, I created this thread with all my NLP posts of this week to give you some technical content for your weekend!

[2 minutes]

1/11🧵
Let's start by What is NLP?



2/11🧵
"What is a Text Embedding?"



3/11🧵
Read 12 tweets
2 Apr
One cool use of NLP is for NER (Named-entity recognition)

This enables you to find person names, organizations, locations, quantities, monetary values, percentages, etc. in a piece of text.

If you only want to use it on your data this API cloud.google.com/natural-langua… can help

1/4🧵
Sometimes you need to create your own model for your specific data corpus (eg: legal, science, medical texts)

To create your own model, AutoML Natural Language can help you:

2/4🧵
If you want to build everything from scratch, then you'll need:
• a language embedding (like BERT, ELMO, USE) and #TFHub have all you need
• a dataset and this github.com/juand-r/entity… can help you find one

3/4🧵
Read 4 tweets
31 Mar
Encoding text in numbers is a very important part of NLP as the better this can be done, the better are the possible results!

Word embedding works but they don't have the full context of the sentence.

This is where BERT comes in

But what is BERT?

1/9🧵
When we do word embedding, both sentences
• They are running a test
• They are running a company

Will have very similar embeddings but the meaning of both sentences are very different. Without this context, the model using this encoding will be blind to the context

2/9🧵
This is where Bidirectional Encoder Representations from Transformers (BERT) comes in play!

It is a Transformer-based network created in 2018 and
takes into account the context of the word's occurrence. For the previous example, it gives very different embeddings.

3/9🧵 Image
Read 9 tweets
27 Mar
If you are looking for something to learn during the weekend,

How about on-device Machine Learning?

You'll only need some understanding of ML and some of Mobile development.

Let me give you all the pointers in FAQ style:

[reading: 5.84 min]

1/12🧵
"Which tools will I need to start?"



2/12🧵
"Ok, how can a ML model run on a phone?"



3/12🧵
Read 13 tweets
25 Mar
To make Apps with Magical User Experiences, you need to get all the performance possible from the hardware.

From the on-device ML perspective, you can achieve that using the TFLite Delegates.

They enable you to access the power of HW acceleration.

1/6🧵
Your phone's CPU is usually very fast but as a multi-purpose processor it's not optimized for the heavy math that ML needs

Like on their big brothers (servers 🤓) phones have also more specialized chips more suitable for ML, the most popular being the GPUs

2/6🧵
Another popular accelerator is the Qualcomm Hexagon DSP that has shown 75% reduction in power consumption.

On the Apple side, you can use the Core ML delegate to access the Neural Engine processor on newer i[Phones|Pads] and that can give huge boosts in performance!

3/6🧵
Read 6 tweets
24 Mar
When we want to deploy a ML models on-device you may need to optimize them.

A model with bigger accuracy might also be bigger in size and also use more memory and slower

Do you need real time inference?

Let's take a look on how to optimize your model

[3.14 minutes]

1/6🧵
TFLite have the model optimization toolkit: tensorflow.org/model_optimiza…
To help you with this very important task.

Among the techniques are: Quantization and Pruning

2/6🧵
Quantization works by reducing the precision of the numbers used to represent a model's parameters, which by default are float32.

This results in a smaller model and faster computation.

More info here: blog.tensorflow.org/2020/04/quanti…

3/6🧵
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!