NLP Basics: Understanding Language Models
NLP Basics: Understanding Language Models
I use in
you
naturally
: may skip some topics suggest
,
# S
NLD
automa
ting the
analysis,
what is NLP ? generation , and acquisition
of human
language .
2 Morphology explores the
word structures and
*
their
Lexemes focuses on [
meaning
> Syntax focuses on sentence
Semantics turns
language [
to actionable or understandable
, can
to
patterns
.
base form .
-
insertion 1
- deletion 1
- Substitution = 2
Language
in the of error correction and
Models
topic spelling
errors there are two types :
correction for
Non-word spelling
tokenization is to break down text to words that are not correct at all (graffe >
-
giraffel
meaningful units .
We have
"type" and we Solution
the
: find words not in
dictionary suggest , words with
type such as
ers . Cats
Real-word spelling
, for words that
are in
dictionary but used in
wrong context
Jessert)
forms.
Noisy Channel
isn't , PhD , $63 51 .
another solution is
a common tokenizer :
BytePair originally a
tokenizer .
In
il
w such that :
tha
M
W =
argmaxP(w(x) is able to capture
=
argmax P(x/w) P(w) .
Syntax
&
-
high
N-grams
memory
order
need much
Computation
&
-have zi
patterns
model
language
perplexity
is
rises which
misspelled
for us
=
2G ↓
or
wrong "Channel" is the way error total number ofwth
,
probability
.
of tokens
is how one misspelled a word The
.
~ N-Gram Probabilities -
Common to follow.
embedding
,
words have of
multiplications of and many types association
log is used so that the
relatedness with each other.
doesn't cause numerical
many probabilities couch bark
underflow (the number would be super small)
I
Synonym -
light
Problem : (Ms assign to unseen uypernymy
- >
-
has
wheel
vehicle car
Smoothi
ing mi &
the solution is
Sequences ,
ponymy part
of
is backoff relationships?
another solution to lower
word
order of is to
represent
N-gram sometimes lowering One
way
a
,
and there is
>
- enables
computing similarity
there is Naive Bayes > Can be learned
defined
-
automatically
logistic Regression which uses
derived from
be
features /number of positive words , embeddings can
more
meaningful associations
reduce noise
I
one method of
Reweighting is tf-id ~ wordzvem
it takes into account both the
frequency how
trains a model to predict
uniqueness of
and the words .
two words close
likely are to appear
to each other The goal is to learn good
TF-IDF TF X IDF .
=
word model .
embettings with this
TF : how
frequent a wordt is document ↓ use two vectors per word :
1 when w is in context
TF(t ,
inAnd
d) 2 when w is an outside word
properties of
:
unique a
embettings
IDF(t) =
1090 toments
witht) -
similarity depends
on
Context size
during training
-words Can have first-order co-occurance
the problem with these
frequency-based or second-order (mutual neighbors
embettings are :
>
they capture relational
meanings
&
-
Neural
LanguageaG in
Simple form : use a feed forward network
and
that predicts next word probability
trains word embeddings .
Recurrent
RNNs can also be used for sentence
Neural
or
Network
Stacked-RNN is a
type of architecture
Bidirectional RNN
whole
and is to look at a
CW causes degrade in output predictions
sequence (not for and the outputs
big CW causes
huge computation . generation)
are
usually concatenated
RNNs can
theoretically preserve arbitery
CW The hidden state is used
long size.
to current taken.
from previous steps process
It * h provides
or Context
a sort of memory
fixed
y
ht -
1
t * the context has no size
&
-
& If
&
A model
Size of
does not
the Context
scale with the
like an
N-gram ,
RNN can be
he g (Uh + Way+ b)
=
used for
through
autoregressive generation
repeated sampling .
Vanishing Gradient
gradient signals from far is lost
away
compared to close signals This . can be
RUNs and cause
a serious problem in
of Gell state-
the same
controlled by three gates
Size as h and C .
and
at each step has an input state a
or
type of certain length- It also
network (in
subsequences
this case two RNs) that over time .
and output
includes max (or average) pooling
take a sequence as input
a
Sequence
S
this
max-pooling over time
goes through
the time dimension of each feature and selects the max
.
and
step of the decoders ,
it's directly connected the CNN networks is parallelized
networks also
optimized for GPU
are
attention to certain These
encoder pay
.
to to
parts of encoder .
mechanism .
Transformers
the good thing about RNNs is that they have no
fixed-length
and
Context window (intheory) but suffer from vanishing gradient
The transformers support parallel
processing of
slow
training
.
inputSeq -
when
attending to
query (including the query
9 = we k - x
,
WK vi = x, W
V
- Feed forward layer for more process
it from
gradient and prevent vanishing
softmax(Rkg
.
· -
layer Norm to keep the weights in
Large
you
Search but Beam is a
general case
Language
down a search tree.
Sampling popular It is
.
is most
to tune between
Models
Probabilistic and allows
But be done
prompt .
Decoding can be
greedy : select
Temperature reshapes the
: Deterministic
word of highest probability probability distribution by dividing logits
by T
Y = Softmax (u/T)
Beam Search is another method .
Vol
probabilities
-
E Softmax -
-- -
-
>
-
= !
- i
- -
skipped
In Beam Search we select the K highest Pretraining
tokens. If K= 2 we select types of Fine-tuning :
Probability Parameter
We and We and feet each to the model continual pretraining & Efficient FT (PEFT)
and sets of profs update some params
again get two new
head to Supervised
adding
FT
Pe and P2 and we
multiply each a
translation ,
sentiment classification , etc
predict word
They aren't trained to next
but similar to
denoising tasks , predicts
the middle of .
tokens in
sequence
tokens needed
how
average
are
many
on
of
for a word . Impacts inference speed
models-
token .
Also last layers can be changed
and fine-tuned .
problem with
large LLMs
Speech
Processing
these models often perform better ,
environmental footprint ,
high cast ,
&
Parameter Sharing
Some
methods -
Pruning
Distillation
multimodality is bridge
to
processing
a
> Knowledge
- speech
Reduce
Computation Mixed Precision
between NLP and
Signal Processing .
Pitch is the
frequency and
Spectrum of Learning
Zero shot one-shot-few-shot-full
fine-tuning
-
example
basic
prompting single
Y
(Read about prompting , Chain-of-thought) higher
frequency
means
higher
Signal is the representation
RLHF
Pitch
of It's
sound waves .
analog by
with
model
nature but
sampling and quantization
1 pre-train can be converted into
digital form
-
2 a In
into numbers
Analog Digital
3 fine-tune based on reward Conversion (ADC)
Signal is first
Sampled and
the quantized.
Audio has
many features we can extract :
Pitch , patterns
rhythm , stress ,
of waveforms ,
zero-crossing
length and loudness,
etc ...
of
typical applications Speech Foundational Models
modeling
Speech & sound transformer-based
general-purpose
speech
models for Speech- a
challenge with
Text >
-
Transformers or RNNS
spectrum or
time-frequency that is feb int
the Decoder
.
by
mel-spectogram .