Data modeling, restructuring, and massaging: Difference between revisions

From Helpful
Jump to navigation Jump to search
Line 399: Line 399:
and e.g. 'fish' and 'fishing' will smush into each other, automatically because otherwise-similar documents will mention both
and e.g. 'fish' and 'fishing' will smush into each other, automatically because otherwise-similar documents will mention both
{{comment|(looking from the perspective of the other axis, mayne we can also compare documents better, but unless comparing documents was your goal, that was actually something we were trying to get rid of)}}
{{comment|(looking from the perspective of the other axis, mayne we can also compare documents better, but unless comparing documents was your goal, that was actually something we were trying to get rid of)}}
 
-->
 


=====Word embeddings=====
=====Word embeddings=====


<!--
The above arrived in an area where those vectors no longer represent just the words,
The above arrived in an area where those vectors no longer represent just the words,
but contain some comparability to similar words.
but contain some comparability to similar words.
Line 472: Line 472:




---
 
Note that
* you won't really know what these vectors mean.
: You can fish this out, to a degree, because you can compare vectors.
: say, if any given vector compares much better to 'hammer' or to 'see' (e.g. from examples sentences), you can start to figure out what it meant.
 
* the thing you train does not necessarily
 
 
 
 
-->
 
=====Static embeddings=====
<!--


In the context of some of the later developments, the simpler variant implmentations are considered static vectors.
In the context of some of the later developments, the simpler variant implmentations are considered static vectors.
Line 481: Line 495:
* make vocabulary: each word gets an entry
* make vocabulary: each word gets an entry
* learn vector for each item in the vocabulary
* learn vector for each item in the vocabulary
'''Limits of static embeddings'''
We previously mentioned that putting a single number on a word has issues.
We now point out that putting a single vector for a word have some issues.
Yes, a lot of words will get a completely sensible sense.
Yet if we made an enumerated vocabulary, and each item gets a vector, then the saw in "I sharpened the saw" and "we saw a bat" ''will'' be assigned the same vector; same for the bat in "I saw a bat" and "I'll bat an eyelash".
The problem is that ''if'' that vector is treated as the semantic sense, both saws have exactly the same sense.
...probably both the tool quality and the seeing quality,
and any use will tell you it's slightly about tools
{{comment|(by count, most 'saw's are the seeing, something that even unsupervised learning should tell you)}}.
You can imagine it's not really an issue for words like antidisestablishmentarianism.
There's not a lot of varied subtle variation in its use, so you can pretend has one meaning.
But saw, hm.
In theory, it may assign
* a vector to the verb saw that is more related to seeing than to cutting
* a vector to the noun bat that is more related to other animals than it is to sports equipment
That said, that is not a given.
: There's at least four options and it might land on any of them, particularly for a sentence in isolation
: the meanings we propose to be isolated here may get weirdly blended in training
But for similar reasons, if you {{example|table a motion}}, it ''will'' associate in gestures and woodworking, because those are the more common things.
'''"Can't you just have multiple saws, encode 'saw as a verb' differently from 'saw as an implement'?"'''
Sure, now you can ''store'' that, but how do you decide?
There are some further issues from inflections, but ignoring those for now,
a larger problem is that that the whole idea is somewhat circular,
depending on already knowing the correct parse to learn this from.
{{comment|(also knowing which words need this separated treatment, but arguably ''that'' you can figure that out from things that end up being approximated in sufficiently distinct ways or not)}}
In reality, finding the best parse of sentence structure just isn't independent from finding its meaning.
You end up having to do both concurrently.
A lot language is pretty entangled, and needs to be resolved by context of what they do to nearby words - human brevity relies on some ambiguity resolving. And it turns out the most commonly used words often the weirder ones.
This entanglement seems to help thing stay compact, with minimal ambiguity, and without requiring very strict rules.
Natural languages seem to end up balancing amount of rules/exception to reasonable levels {{comment|(even [[conlang]]s like lobjan think about this, though they engineer it explicitly)}}, and has some other uses - like [[double meanings]], and intentionally generalizing meanings.
So we're stuck with compact complexity.
We can try to model absolutely everything we do in each language, and that might even give us something more useful in the end.
'''Yet''' imagine for a moment a system that would just pick up 'saw after a pronoun' and 'saw after a determiner',
and not even because it knows what pronouns or determiners are, but because given a ton of examples,
those are two of the things the word 'saw' happens to often be next to.
Such a system ''also'' doesn't have to know that it is modeling a certain verbiness and nouniness as a result.
It might, from different types of context, perhaps learn that one of these contexts relates it to a certain tooliness as well.
But, not doing that on purpose, such a system won't and ''can't'' explain such aspects.
So why mention such a system? Why do that at all?
Usually because it learns these things without us telling it anything, and the similarity it ends up helping things like:
: "if I search for walk, I also get things that mention running",
: "this sentence probably says something about people moving"
: "walk is like run, and to a lesser degree swim",
: "I am making an ontology style system, and would like some assistance to not forget adding related things"
The "without us telling it anything" -- it being an [[unsupervised]] technique -- also matters.
You will probably get more precise answers with the same amount of well-annotated data.
You will probably get equally good answers with less annotated data.
But the thing is that annotated data is hard and expensive, because it's a lot of work.
And you can have endless discussions about annotation ''because'' these is ambiguity in there, so there's probably an upper limit, or even more time spent.
'''It's just easier to have ''a lot more''' un-annotated data''',
so even if it needs ''so much more'' text, a method that then does comparably well is certainly useful.
You just feed it lots of text.
XXX
This is not a solution to all of the underlying issues here. We're not even trying to solve them all,
in fact we're just going to gloss over a lot of them,
to a point where we can maybe encode multiple uses of words (and if they have a single one, great!).
There are limitations, some upsides that are arguably also downsides.
It might pick up on more subtleties, but like any unsupervised technique,
and tends to be better at finding things that at describing ''what'' it found.
It may pick up relations only softly,
and in ways you can't easily extract or learn from,
but it's pretty good at not completely missing them,
meaning you don't have to annotate half the world's text with precise meaning
for it to work.
Word embedding are usually explained as "vector representation for a word"
Such vectors are useful for things like subject similarity, sentiment analysis, syntactic parsing,
The fact that it's a vector isn't that important.
It happens to be mathematically handy to work with,
and we happen to want to end up with vector values where similar vectors ''hopefully'' carry similar meanings.
'Embeddings' is a bit of a strange term for that concept,
and seems to point out (with most methods we use today) how training these considered their context
And when using the same to figure out what unseen text means, it may well assign the tool-ish sense, or the verb-ish sense, on similar context.
In fact, some patterns are strong enough that even unseen words will get a decent estimation.
Say, give we spoiaued to an embedding-style parser, and it's going to guess it's a verb ''while also'' pointing out it's out of its vocabulary.




Line 487: Line 652:
=====Contextual word embeddings=====
=====Contextual word embeddings=====
<!--
<!--


The first attempts at word embeddings, and many since,
The first attempts at word embeddings, and many since,
Line 501: Line 667:




Consider "we saw a bat".
In theory, it may assign
* a vector to the verb saw that is more related to seeing than to cutting
* a vector to the noun bat that is more related to other animals than it is to sports equipment
That said, that is not a given.
: There's at least four options and it might land on any of them, particularly for a sentence in isolation
: the meanings we propose to be isolated here may get weirdly blended in training




Line 652: Line 809:
-->
-->


=====vectors - unsorted=====
<!--
These vectors come from machine learning (of varying type and complexity).
* LSA
* [[word2vec]] -
: technically patented?
: T Mikolov et al. (2013) "Efficient Estimation of Word Representations in Vector Space"
* tok2vec
* FastText
: https://fasttext.cc/
* lda2vec
: https://multithreaded.stitchfix.com/blog/2016/05/27/lda2vec/#topic=38&lambda=1&term=
All of this may still apply a single vector to the same word always (sometimes called static word embeddings).
This is great for unambiguous content words, but less so for polysemy and
-->


<!--
<!--

Revision as of 13:53, 29 March 2024

This is more for overview of my own than for teaching or exercise.

Overview of the math's areas

Arithmetic · 'elementary mathematics' and similar concepts
Set theory, Category theory
Geometry and its relatives · Topology
Elementary algebra - Linear algebra - Abstract algebra
Calculus and analysis
Logic
Semi-sorted
: Information theory · Number theory · Decision theory, game theory · Recreational mathematics · Dynamical systems · Unsorted or hard to sort


Math on data:

  • Statistics as a field
some introduction · areas of statistics
types of data · on random variables, distributions
Virtues and shortcomings of...
on sampling · probability
glossary · references, unsorted
Footnotes on various analyses


  • Other data analysis, data summarization, learning
Data modeling, restructuring, and massaging
Statistical modeling · Classification, clustering, decisions, and fuzzy coding ·
dimensionality reduction ·
Optimization theory, control theory · State observers, state estimation
Connectionism, neural nets · Evolutionary computing
  • More applied:
Formal grammars - regular expressions, CFGs, formal language
Signal analysis, modeling, processing
Image processing notes



Intro

NLP data massage / putting meanings or numbers to words

Bag of words / bag of features

The bag-of-words model (more broadly bag-of-features model) use the collection of words in a context, unordered, in a multiset, a.k.a. bag.

In other words, we summarize a document (or part of it) it by appearance or count of words, and ignore things like adjacency and order - so any grammar.



In text processing

In introductions to Naive Bayes as used for spam filtering, its naivety essentially is this assumption that feature order does not matter.


Though real-world naive bayes spam filtering would take more complex features than single words (and may re-introduce adjacenct via n-grams or such), examples often use 1-grams for simplicity - which basically is bag of words, exc.

Other types of classifiers also make this assumption, or make it easy to do so.


Bag of features

While the idea is best known from text, hence bag-of-words, you can argue for bag of features, applying it to anything you can count, and may be useful even when considered independently.

For example, you may follow up object detection in an image with logic like "if this photo contains a person, and a dog, and grass" because each task may be easy enough individually, and the combination tends to narrow down what kind of photo it is.


In practice, the bag-of-features often refers to models that recognize parts of a whole object (e.g. "we detected a bunch of edges of road signs" might be easier and more robust than detecting it fully), and used in a number image tasks, such as feature extraction, object/image recognition, image search, (more flexible) near-duplicate detection, and such.

The idea that you can describe an image by the collection of small things we recognize in it, and that combined presence is typically already a strong indicator (particularly when you add some hypothesis testing). Exact placement can be useful, but often easily secondary.


See also:

N-gram notes

N-grams are contiguous sequence of length n.


They are most often seen in computational linguistics.


Applied to sequences of characters it can be useful e.g. in language identification, but the more common application is to words.

As n-grams models only include dependency information when those relations are expressed through direct proximity, they are poor language models, but useful to things working off probabilities of combinations of words, for example for statistical parsing, collocation analysis, text classification, sliding window methods (e.g. sliding window POS tagger), (statistical) machine translation, and more


For example, for the already-tokenized input This is a sentence . the 2-grams would be:

This   is
is   a
a   sentence
sentence   .


...though depending on how special you do or do not want to treat the edges, people might fake some empty tokens at the edge, or some special start/end tokens.


Skip-grams

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

Note: Skip-grams seem to refer to now two different things.


An extension of n-grams where components need not be consecutive (though typically stay ordered).


A k-skip-n-gram is a length-n sequence where the components occur at distance at most k from each other.


They may be used to ignore stopwords, but perhaps more often they are intended to help reduce data sparsity, under a few assumptions.

They can help discover patterns on a larger scale, simply because skipping makes you look further for the same n. (also useful for things like fuzzy hashing).


Skip-grams apparently come from speech analysis, processing phonemes.


In word-level analysis their purpose is a little different. You could say that we acknowledge the sparsity problem, and decide to get more out of the data we have (focusing on context) rather than trying to smooth.

Actually, if you go looking, skip-grams are now often equated with a fairly specific analysis.



Syntactic n-grams

Flexgrams

Words as features - one-hot coding and such

Putting numbers to words

Computers and people and numbers

vector space representations, word embeddings, and more

Word embeddings
Static embeddings
Contextual word embeddings
Subword embeddings
Bloom embeddings, a.k.a. the hash trick
Now we have nicer numbers, but how how I use them?
vectors - unsorted

Moderately specific ideas and calculations

Collocations

Collocations are statistically idiosyncratic sequences - the math that is often used asks "do these adjacent words occur together more often than the occurrence of each individually would suggest?".

This doesn't ascribe any meaning, it just tends to signal anything from empty habitual etiquette, jargon, various substituted phrases, and many other things that go beyond purely compositional construction, because why other than common sentence structures would they co-occur so often?

...actually, there are varied takes on how useful collocations are, and why.


latent semantic analysis

Latent Semantic Analysis (LSA) is the application of Singular Value Decomposition on text analysis and search.


random indexing

https://en.wikipedia.org/wiki/Random_indexing


Topic modeling

Roughly the idea given documents that are about a particular topic, one would expect particular words to appear in the each more or less frequently.

Assuming such documents sharing topics, you can probably find groups of words that belong to those topics.

Assuming each document is primarily about one topic, you can expect a larger set of documents to yield multiple topics, and an assignment of one or more of these topics, so act like a soft/fuzzy clustering.

This is a relatively weak proposal in that it relies on a number of assumptions, but given that it requires zero training, it works better than you might expect when those assumptions are met. (the largest probably being your documents having singular topics).


https://en.wikipedia.org/wiki/Topic_model


word2vec

This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.

word2vec is one of many ways to put semantic vectors to words (in the distributional hypothesis approach), and refers to two techniques, using either bag-of-words and skip-gram as processing for a specific learner, as described in T Mikolov et al. (2013), "Efficient Estimation of Word Representations in Vector Space", probably the one that kicked off this dense-vector idea into the interest.


Word2vec amounts could be seen as building a classifier that predicts what word apear in a context, and/or what context appears around a word, which happens to do a decent task of classifying that word.


That paper mentions

  • its continuous bag of words (cbow) variant predicts the current word based on the words directly around it (ignoring order, hence bow(verify))
  • its continuous skip-gram variant predicts surrounding words given the current word.
Uses skip-grams as a concept/building block. Some people refer to this technique as just 'skip-gram' without the 'continuous',

but this may come from not really reading the paper you're copy-pasting the image from?

seems to be better at less-common words, but slower


(NN implies one-hot coding, so not small, but it turns out to be moderately efficient(verify))


GloVe