Latest / CyberSecurity Summary / Natural Language Processing with Java: Techniques for building machine learning and neural network models for NLP, 2nd Edition
Transcript
- 0:00Speaker 1: Okay, let's try and unpack this. Imagine just for a second,
- 0:04Speaker 1: the sheer, staggering amount of text data we all generate
- 0:08Speaker 1: every single day.
- 0:09Speaker 2: It's unbelievable.
- 0:10Speaker 1: Really, Yeah, emails, social media posts, articles, research papers, I mean,
- 0:15Speaker 1: even just our normal conversations like this massive digital ocean
- 0:19Speaker 1: of words. Absolutely, but how do computers, these logical binary machines,
- 0:25Speaker 1: how do they actually make any sense of it all?
- 0:27Speaker 1: How do they read it, understand it, maybe even respond.
- 0:30Speaker 2: Well, that's exactly where natural language processing comes in NLP, right, NLP.
- 0:35Speaker 2: It's this really fascinating field dedicated to helping computers interact
- 0:40Speaker 2: with and analyze natural human languages like the ones we speak.
- 0:43Speaker 1: And what's really interesting you were saying, is how it
- 0:45Speaker 1: pulls from so many different areas.
- 0:47Speaker 2: Exactly, what's truly fascinating here is how this field bridges
- 0:51Speaker 2: so many different disciplines. Our deep dive today is based
- 0:54Speaker 2: on a pretty solid source natural language processing with Java
- 0:57Speaker 2: second edition, and our mission really is to pull out
- 1:01Speaker 2: the most important bits of knowledge and insight for you,
- 1:03Speaker 2: the listener. Because NLP is well, it's multidisciplinary. It draws
- 1:09Speaker 2: heavily from computer science, artificial intelligence AI, and also formal linguistics,
- 1:15Speaker 2: and we're talking about the tech behind things you use
- 1:17Speaker 2: constantly search engines obviously, but also automated help systems chatbots.
- 1:22Speaker 1: Well yeah, those.
- 1:23Speaker 2: Even really complex projects. Remember IBM's Watson playing Jeopardy.
- 1:27Speaker 1: That kind of thing. Wow. Okay, So when we talk
- 1:30Speaker 1: about natural language processing y NLP, what is it fundamentally?
- 1:36Speaker 1: What does it actually do well?
- 1:38Speaker 3: At its core?
- 1:38Speaker 2: The formal definition involves using computer science AI and linguistics
- 1:42Speaker 2: to analyze natural language. Okay, but maybe a more useful
- 1:46Speaker 2: way to think about it is it's like a sophisticated toolkit,
- 1:49Speaker 2: a set of tools designed to pull out meaningful, useful
- 1:52Speaker 2: information from all that messy unstructured language data. You know,
- 1:56Speaker 2: web pages, documents, tweet streams.
- 1:58Speaker 1: Right, unstructured meaning like a neat database.
- 2:01Speaker 2: Table precisely, And every time you type a query into
- 2:03Speaker 2: Google or bing, NLP is humming away behind the scenes.
- 2:07Speaker 2: It's translating your human question into something the computer can
- 2:10Speaker 2: actually act on to get you the results you want.
- 2:13Speaker 1: And to do that, it has to deal with, well,
- 2:15Speaker 1: the fundamentals of language itself. We often hear words like
- 2:18Speaker 1: syntax and semantics. Could you break those down a bit
- 2:22Speaker 1: in the NLP context, I mean, and why is it
- 2:24Speaker 1: so important to make that distinction?
- 2:25Speaker 3: Sure?
- 2:26Speaker 2: So, syntax that's basically the grammar, the rules for how
- 2:30Speaker 2: you put words together to make a valid sentence. For instance,
- 2:33Speaker 2: in English, tim hit the ball works tactically correct, but
- 2:38Speaker 2: hit ball, Tim, that just doesn't fly.
- 2:40Speaker 3: The syntax is wrong.
- 2:41Speaker 1: Okay, So that's structure exactly.
- 2:43Speaker 2: Then you have semantics, and that's about the meaning of
- 2:46Speaker 2: the words and the sentences themselves.
- 2:48Speaker 1: It's a meaning that sounds harder it is.
- 2:50Speaker 2: And this isn't just you know, a linguistic detail. It's
- 2:53Speaker 2: arguably the mount Everest for NLP because the real challenge
- 2:57Speaker 2: isn't just sorting words correctly, it's understanding the world those
- 3:01Speaker 2: words are describing. Without getting the semantics. A computer could
- 3:04Speaker 2: index a million tweets about a movie maybe, but it
- 3:07Speaker 2: couldn't tell you if people genuinely liked it or if
- 3:09Speaker 2: they were just being sarcastic.
- 3:11Speaker 1: Uh sarcasm. Yeah, computers must hate.
- 3:13Speaker 3: That they do.
- 3:15Speaker 2: It's the difference between just processing data and actually grasping
- 3:18Speaker 2: human intent. And this is super important now because of
- 3:22Speaker 2: the sheer volume of unstructured stuff out there, blogs, tweets,
- 3:27Speaker 2: social media. You need to understand it, not just file
- 3:31Speaker 2: it away.
- 3:32Speaker 1: It sounds incredibly complex. I mean, human language is so
- 3:36Speaker 1: well messy, isn't it. Yeah, compared to rigid computer code.
- 3:39Speaker 1: What are some of those really fundamental, maybe frustratingly subtle
- 3:43Speaker 1: challenges that make NLP so difficult.
- 3:45Speaker 2: You've absolutely nailed the core problem. Natural languages are just
- 3:48Speaker 2: full of nuance and ambiguity. They're not precisely Python or Java.
- 3:51Speaker 2: I mean, one obvious thing is just the sheer number
- 3:53Speaker 2: of languages, hundreds of them, each with its own syntax,
- 3:56Speaker 2: its own quirks.
- 3:57Speaker 1: Yeah, that a lot.
- 3:57Speaker 2: But even within one language like English, WI, the challenges
- 4:01Speaker 2: are well profound. Take ambiguity. Words often have multiple meanings.
- 4:04Speaker 2: Think about home could be your house, could be your hometown,
- 4:06Speaker 2: could be home base in baseball. NLP systems have to
- 4:10Speaker 2: perform something called word sense disambiguation WSD to treat and
- 4:13Speaker 2: figure out the intended meaning from.
- 4:15Speaker 1: The context WSD.
- 4:17Speaker 2: And then there's coreference. That's where different words or pronouns
- 4:19Speaker 2: refer back to the same thing. Like in the city
- 4:22Speaker 2: is large but beautiful, it fills the entire valley. It
- 4:26Speaker 2: clearly refers to the city. Humans get that instantly, computers
- 4:30Speaker 2: not so easy, I see.
- 4:32Speaker 3: But the subtle problems.
- 4:33Speaker 2: Go even deeper into things we barely notice, like punctuation.
- 4:38Speaker 1: Punctuation really like commas and periods exactly?
- 4:42Speaker 2: A period seems simple, right, But it could end a sentence,
- 4:46Speaker 2: or it could end in abbreviation like mister or missus h.
- 4:49Speaker 2: Or it could be part of a number like three
- 4:51Speaker 2: point one four nine or part of an ellipsis you
- 4:56Speaker 2: know the three dots? Never really thought about thattions themselves
- 5:00Speaker 2: are tricky? Is it CIA or CIA with periods? How
- 5:03Speaker 2: does the machine know? Then You've got sentences inside quotes
- 5:06Speaker 2: or totally different conventions in tweets or chat messages where
- 5:09Speaker 2: line breaks mean something else. Wow, Even simple things contractions
- 5:12Speaker 2: like can't or don't?
- 5:14Speaker 3: How do you split that? Is it one token or two?
- 5:16Speaker 2: What about hyphenated words like first cut.
- 5:19Speaker 3: And don't forget?
- 5:20Speaker 2: Numbers are special characters mixed in with words like iPhone
- 5:23Speaker 2: five s or a web address or an email?
- 5:26Speaker 1: Wow? Okay, so it sounds like even the simplest things
- 5:29Speaker 1: like a single period can be a total mindfield for
- 5:32Speaker 1: a computer trying to understand text. What's the common thread here?
- 5:37Speaker 1: What makes all these little details so tricky.
- 5:39Speaker 2: I think the common thread is context and frankly human intuition.
- 5:44Speaker 2: We just effortlessly figure this stuff out using the surrounding
- 5:47Speaker 2: information and our world knowledge. But for a computer, each
- 5:50Speaker 2: of these is like a tiny decision point where it
- 5:52Speaker 2: needs to apply some rule or a statypical guess right.
- 5:56Speaker 1: Okay, So given all these complexities, what does this actually
- 5:58Speaker 1: mean for building systems that you know, process language? How
- 6:02Speaker 1: do we even start to tackle this massive ocean of words?
- 6:05Speaker 2: Well, the good news is that even the most complex
- 6:07Speaker 2: NLP applications are usually built up from a set of
- 6:10Speaker 2: fundamental techniques, building blocks, if you will. These often work
- 6:14Speaker 2: together in sequence in what we call a pipeline pipeline,
- 6:17Speaker 2: and the very first step usually is finding the parts
- 6:20Speaker 2: of the text. This covers two main things, tokenization and normalization.
- 6:25Speaker 1: Tokenization breaking into tokens like words exactly.
- 6:30Speaker 2: Tokenization is absolutely fundamental. It's breaking down that raw stream
- 6:34Speaker 2: of text into individual units.
- 6:36Speaker 3: We call tokens.
- 6:37Speaker 2: Usually these are words, but sometimes they can be smaller
- 6:40Speaker 2: things too, like morphemes, more fe Yeah, the smallest bits
- 6:44Speaker 2: of a word that still have meaning, like the unbreakable
- 6:48Speaker 2: or the ed suffix in bounded aw or tokens could
- 6:52Speaker 2: be bigger, like multi word phrases that act as a
- 6:55Speaker 2: single unit, but yeah, mostly think words. NLP also has
- 6:59Speaker 2: to fit figure out how to handle things like abbreviations, contractions, numbers,
- 7:03Speaker 2: and even you know, synonyms different words meaning the same thing.
- 7:06Speaker 1: And normalization what's that about?
- 7:08Speaker 2: So once you have your tokens, normalization is basically cleaning
- 7:11Speaker 2: them up. It's essential preprocessing a lot of NLP tools
- 7:14Speaker 2: and APIs they kind of assume the data coming in
- 7:17Speaker 2: is already clean and consistent.
- 7:19Speaker 1: Right, makes sense.
- 7:19Speaker 2: So normalization involves things like converting everything to lowercase so
- 7:23Speaker 2: the and the are treated the same, removing stop words,
- 7:26Speaker 2: those really common words like the is as which often
- 7:30Speaker 2: don't add much unique meaning for analysis. Okay, and then
- 7:33Speaker 2: we get into stemming. This is reducing words down to
- 7:37Speaker 2: their root form, so like running, runs and ran might
- 7:40Speaker 2: all get reduced down to just run. There's a famous
- 7:44Speaker 2: algorithm called the porter stemmer for this.
- 7:46Speaker 1: Okay, stemming, got it.
- 7:47Speaker 2: And then there's something a bit more sophisticated called lemmatization.
- 7:51Speaker 3: This tries to find.
- 7:52Speaker 2: The actual dictionary form or lemma of a word. So,
- 7:56Speaker 2: for example, the lemma of was is actually.
- 7:59Speaker 1: B ah ah, I see the difference. Stemming is cruder,
- 8:03Speaker 1: limitization is more linguistically aware exactly.
- 8:06Speaker 2: Tools like Stanford Core NLP or open NLP have modules
- 8:10Speaker 2: that can do this limitization pretty well.
- 8:12Speaker 1: Okay, so we've broken the text into its basic atom,
- 8:15Speaker 1: the tokens, the words. But language isn't just a jumble
- 8:18Speaker 1: of words, right, It's structured into sentences, into ideas. You'd
- 8:21Speaker 1: think finding sentences would be easy, just look for a period,
- 8:24Speaker 1: question mark, exclamation point. But I suspect it's not that simple.
- 8:28Speaker 2: You suspect correctly, it's definitely not that simple. This process
- 8:31Speaker 2: is called sentence boundary disambigraation SBDSBD, and the difficulty, as
- 8:36Speaker 2: you pointed out earlier, comes right back to the ambiguity
- 8:39Speaker 2: of punctuation, especially the humble period. It ends sentences, sure,
- 8:44Speaker 2: but it also ends abbreviations. Mister appears in numbers three
- 8:48Speaker 2: point one four, talk by four signifies emissions, ellipses.
- 8:51Speaker 1: Right, the list goes on.
- 8:53Speaker 2: So imagine the sentence mister and missus Smith went to Washington.
- 8:56Speaker 2: Those first two periods don't end sentences. No, yetting SBD
- 9:00Speaker 2: write is crucial because many of the next steps in
- 9:03Speaker 2: an NLP pipeline, like assigning parts of speech or finding
- 9:06Speaker 2: named entities. They typically operate on one sentence at a time.
- 9:10Speaker 1: Okay, so if you split the sentence wrong.
- 9:12Speaker 2: Exactly, you can completely mess up the downstream analysis. You
- 9:14Speaker 2: might confuse he walked over the hill was steep with
- 9:18Speaker 2: the single phrase over the hill totally different.
- 9:20Speaker 1: Meaning yikes. How do they handle it? Then?
- 9:22Speaker 2: Well?
- 9:23Speaker 3: There are different approaches. Some are rule based.
- 9:25Speaker 2: Linpipe, for example, has something called a heuristic sentence model.
- 9:29Speaker 2: It uses clever lists like sets of words that are
- 9:32Speaker 2: possible stops at the end of a sentence, words that
- 9:34Speaker 2: are impossible just before a period penultimates, and words that
- 9:38Speaker 2: are impossible at the start of a new sentence, plus
- 9:41Speaker 2: flags for things like balancing parentheses or quotes.
- 9:44Speaker 1: Wow, that sounds like detective work.
- 9:46Speaker 2: It kind of is using lots of rules and heuristics
- 9:49Speaker 2: to make the best guess.
- 9:50Speaker 1: Okay, this is where it gets really interesting for me.
- 9:52Speaker 1: We've got words, we've got sentences. How do computers go
- 9:56Speaker 1: beyond that to actually pick out the key things in
- 9:59Speaker 1: the text? The who? What? Where? How does it know
- 10:02Speaker 1: Apple is the company in one sentence and the fruit
- 10:04Speaker 1: in another.
- 10:05Speaker 2: Right, that's the job of named entity recognition or ner
- 10:08Speaker 2: ANR ANYR is the process of finding mentions of entities,
- 10:12Speaker 2: typically things like people, places, organizations, dates, money, time, and
- 10:18Speaker 2: classifying them, tagging them with their specific category.
- 10:21Speaker 1: Why is that hard? Seems like you could.
- 10:23Speaker 2: Use lists lists help, but names themselves are ambiguous. Is
- 10:26Speaker 2: penny a person's name or a coin?
- 10:28Speaker 1: Good? Point?
- 10:29Speaker 3: Is Georgia the.
- 10:31Speaker 2: US state, the country or maybe even a person's name.
- 10:35Speaker 3: Context is everything?
- 10:37Speaker 1: Context again yep, and.
- 10:39Speaker 2: Entities can be mentioned in different ways IBM versus international
- 10:43Speaker 2: business machines. The system needs to know those referred to
- 10:46Speaker 2: the same organization.
- 10:48Speaker 1: So how do they do NR? Lists and well?
- 10:51Speaker 2: There are broadly two main approaches. One is rule based,
- 10:55Speaker 2: where human experts rate detailed rules or use large predefined
- 10:58Speaker 2: lists gas tears. They're sometimes called The other approach, which
- 11:02Speaker 2: is very common now, is machine learning. These systems learn
- 11:06Speaker 2: patterns from huge amounts of texts that have already been
- 11:08Speaker 2: annotated with entities. They use statistical models examples exactly, and
- 11:12Speaker 2: for common structured entities you can sometimes use regular expressions
- 11:16Speaker 2: those pattern matching rules to find things like phone numbers, URLs,
- 11:20Speaker 2: zip codes, email addresses, maybe even specific time and date.
- 11:24Speaker 1: Formats Okay, so we found the entities. What about the
- 11:27Speaker 1: other words, Like, how do we get computers to understand
- 11:29Speaker 1: the grammar? What's a noun, what's a verb, adjective? And
- 11:33Speaker 1: why does that actually matter for understanding?
- 11:35Speaker 2: Yeah, that's crucial too. This is done using part of
- 11:37Speaker 2: speech tagging or POS tagging.
- 11:39Speaker 1: POS tagging.
- 11:41Speaker 2: It's the process of assigning a grammatical tag like noun, verb, adjective, preposition, pronoun, adverb, conjunction,
- 11:47Speaker 2: interjection to each word in a sentence.
- 11:50Speaker 1: Why do we need that?
- 11:51Speaker 2: It's really important for figuring out the context of a
- 11:53Speaker 2: word and its role in the sentence structure. Knowing if
- 11:56Speaker 2: book is a noun or a verb changes everything.
- 11:59Speaker 1: True book the flight versus read the book precisely.
- 12:02Speaker 2: But even POS tagging has challenges. Remember normalization. If you
- 12:06Speaker 2: lowercase everything, you might confuse sam the word with sam
- 12:10Speaker 2: the name a proper noun. Contractions again, can't hyphenated words,
- 12:14Speaker 2: State of the art, embedded numbers version five, weird character
- 12:19Speaker 2: sequences like URLs.
- 12:21Speaker 3: They all make POS tagging harder.
- 12:23Speaker 1: So how are the tags assigned? Is there a standard?
- 12:25Speaker 2: There are several tag sets, but a very common one
- 12:28Speaker 2: is the pen Treebank tag set. It uses short tags
- 12:31Speaker 2: like nn for a singular noun, n NS for plural noun,
- 12:34Speaker 2: VBD for a past tense verb, jj for an adjective,
- 12:37Speaker 2: and so on. And to train these pos tagging models,
- 12:41Speaker 2: you need a corpus that's a large body of text
- 12:44Speaker 2: that has already been manually tagged with the correct parts
- 12:47Speaker 2: of speech. Famous examples are the Brown corpus or the
- 12:50Speaker 2: British National corpus. The models learn from these labeled examples.
- 12:54Speaker 1: Okay, this is fascinating. We've identified words, sentences, entities, grammar.
- 12:59Speaker 1: Let's shift focus a bit. How do computers go beyond
- 13:02Speaker 1: just identifying these pieces? How do they actually represent the text,
- 13:06Speaker 1: especially the meaning in context for deeper analysis?
- 13:09Speaker 2: Right moving towards representation, this brings us to two really
- 13:12Speaker 2: important concepts, feature engineering and word embedding.
- 13:15Speaker 1: Future engineering sounds like something out of AI.
- 13:18Speaker 3: It is very much so.
- 13:20Speaker 2: Feature engineering is essentially the art and it is still
- 13:23Speaker 2: something of an art of transforming raw data into numerical
- 13:26Speaker 2: features that machine learning algorithms can actually work with. It
- 13:29Speaker 2: requires using domain knowledge to select or create the right
- 13:32Speaker 2: features that will help the algorithm learn effectively. It's still
- 13:36Speaker 2: a very human driven process in many ways.
- 13:38Speaker 1: Okay, and how does that apply to text? Well.
- 13:40Speaker 2: One common technique in text feature engineering is using n grams.
- 13:44Speaker 1: N grams.
- 13:44Speaker 2: Yeah, n grams are simply sequences of n consecutive words
- 13:48Speaker 2: from the text.
- 13:49Speaker 3: So if you have the sentence this is an.
- 13:51Speaker 2: N gram model, A two gram or big gram would
- 13:54Speaker 2: be this is is an n ergram n gram model,
- 13:57Speaker 2: A three gram traegram would be this is an is
- 14:00Speaker 2: an anagram an n gram model.
- 14:02Speaker 1: Okay. Sequences of words? Why are they useful?
- 14:04Speaker 2: They help capture a bit more context than just single words.
- 14:08Speaker 2: They help us estimate the probability of a word sequence occurring.
- 14:11Speaker 2: This is often used to predict the next word in
- 14:14Speaker 2: a sequence, maybe for autocomplete. Many models use the Markov
- 14:17Speaker 2: assumption here, the idea that the probability of the next
- 14:20Speaker 2: word depends only on the previous one or few words.
- 14:23Speaker 1: Right, I like on my phone keyboard exactly.
- 14:25Speaker 3: But then we get to word embedding.
- 14:27Speaker 2: This is a really powerful set of techniques for how
- 14:30Speaker 2: computers can deal with the context and meaning of words
- 14:33Speaker 2: in a more sophisticated way.
- 14:35Speaker 1: Embedding like putting words into some kind of space.
- 14:38Speaker 2: That's a great way to think about it. The goal
- 14:40Speaker 2: is to represent words as numerical vectors lists of numbers
- 14:44Speaker 2: in a high dimensional space, and the key idea is
- 14:47Speaker 2: that words with similar meanings should have similar vector representations.
- 14:50Speaker 2: They should be close to each other in this space.
- 14:53Speaker 1: So king and queen would be close. Yeah, and maybe
- 14:56Speaker 1: Apple and banana.
- 14:57Speaker 2: Precisely, but Apple the company should be closer to say
- 15:01Speaker 2: Microsoft or Google than to banana.
- 15:04Speaker 1: Okay.
- 15:05Speaker 2: The aim is to capture not just context, but also
- 15:08Speaker 2: maybe hierarchical relationships like king, queen, prince and morphological information
- 15:13Speaker 2: like run run a grant.
- 15:14Speaker 1: How do they create these embeddings?
- 15:15Speaker 2: There are two main families of approaches. First, frequency based embedding.
- 15:19Speaker 2: These rely on counting how often words appear together simple
- 15:22Speaker 2: counts like an account vector, or more sophisticated methods like
- 15:26Speaker 2: tf IDF.
- 15:27Speaker 1: Tf IDF I've heard of that way.
- 15:29Speaker 2: Yeah, it's very common, especially in information retrieval. It stands
- 15:32Speaker 2: for term frequency inverse document frequency. It combines two scores.
- 15:37Speaker 2: Tf term frequency is just how often a word appears
- 15:40Speaker 2: in a single document simple count IDF. Inverse document frequency
- 15:44Speaker 2: measures how important that word is across the entire collection
- 15:47Speaker 2: of documents. The idea is that words appearing in many
- 15:51Speaker 2: many documents like the is A are less informative than
- 15:54Speaker 2: words appearing in only a few so rare words get
- 15:58Speaker 2: a higher IDF score.
- 15:59Speaker 1: Ah, So it balances frequency within a document with rarity
- 16:03Speaker 1: across all documents exactly.
- 16:04Speaker 2: The combined TFIDF score helps rank how relevant a document
- 16:08Speaker 2: is to a query. For example, it gives more weight
- 16:11Speaker 2: to terms that are frequent in that document but relatively
- 16:14Speaker 2: rare overall.
- 16:15Speaker 1: Makes sense and the other type of embedding.
- 16:17Speaker 2: The second type is prediction based embedding. These methods typically
- 16:21Speaker 2: use neural networks and try to predict a word based
- 16:23Speaker 2: on its neighbors, or predict the neighbors based on the word.
- 16:26Speaker 2: This is where you hear names like word to vac, glove, cbow,
- 16:30Speaker 2: continuous bag of words, and skip gram models. They often
- 16:33Speaker 2: capture more subtle semantic relationships than frequency based methods.
- 16:37Speaker 1: Okay, neural networks getting involved. So these embeddings create these
- 16:40Speaker 1: complex vector representations. You mentioned high dimensional space. How high
- 16:44Speaker 1: are we talking? Does that cause problems?
- 16:46Speaker 3: Oh? It absolutely causes problems.
- 16:49Speaker 2: We're often talking about vectors with hundreds, sometimes even thousands
- 16:53Speaker 2: of dimensions for each word.
- 16:55Speaker 1: Wow.
- 16:55Speaker 2: Now imagine you have a vocabulary of a million words.
- 16:58Speaker 2: Each with a three hundred dimension. That requires a lot
- 17:02Speaker 2: of memory over six gigabytes in that example and computation,
- 17:05Speaker 2: it can become impractical.
- 17:06Speaker 1: Yeah, I can see that, So what do you do?
- 17:08Speaker 2: This is where dimensionality reduction techniques come in. We need
- 17:12Speaker 2: ways to reduce the number of dimensions while preserving as
- 17:15Speaker 2: much of the important information as.
- 17:16Speaker 1: Possible, like summarizing the dimensions sort of.
- 17:19Speaker 2: One classic technique is principal component analysis or PCA. PCA
- 17:24Speaker 2: is a linear algorithm. It looks for the directions in
- 17:27Speaker 2: the data where the variance is highest the principal components,
- 17:31Speaker 2: and projects the data onto a lower dimensional subspace defined
- 17:34Speaker 2: by those components. It basically tries to find the main
- 17:37Speaker 2: axis of variation and discard the less important ones.
- 17:40Speaker 1: Okay, linear finds the main trends.
- 17:42Speaker 2: Right, But sometimes the relationships between words their meanings aren't
- 17:46Speaker 2: purely linear. They might be clustered in more complex ways.
- 17:50Speaker 2: That's where nonlinear techniques like t distributed stochastic neighbor embedding
- 17:54Speaker 2: or tSNE come.
- 17:56Speaker 1: In tSNE that sounds fancy, it is quite sophisticated.
- 18:01Speaker 2: It's a non linear, non deterministic, meaning you might get
- 18:04Speaker 2: slightly different results each time. You run it algorithm. It's
- 18:07Speaker 2: particularly good at creating two D or three D maps
- 18:10Speaker 2: of high dimensional data that preserve the local structure, meaning
- 18:14Speaker 2: points that are close together in the high dimensional space
- 18:17Speaker 2: tend to remain close together in the low dimensional map.
- 18:19Speaker 1: So it's good for visualization seeing clusters of words exactly.
- 18:23Speaker 2: PCA is maybe better for just raw compression sometimes, but
- 18:26Speaker 2: TSSE is fantastic for visualizing and exploring complex relationships in
- 18:30Speaker 2: data like word embeddings. It's really good at finding structure
- 18:33Speaker 2: that other algorithms might miss because it's so flexible.
- 18:36Speaker 1: That's a great comparison. Okay, So once we've processed words
- 18:40Speaker 1: maybe represented them with these embeddings, how do we classify
- 18:45Speaker 1: entire pieces of text? It's like, is this news article
- 18:47Speaker 1: about sports or politics? Is this customer review positive or negative? Right?
- 18:52Speaker 2: Moving up to the document level, this involves task like
- 18:55Speaker 2: text classification, sentiment analysis, and language identification.
- 18:58Speaker 1: Okay, let's take those one by one. Text classification.
- 19:01Speaker 2: Text classification is pretty straightforward conceptually. It's about assigning a
- 19:07Speaker 2: piece of text, could be a sentence, paragraph, document, to
- 19:11Speaker 2: one or more pre defined categories. Classic example spam detection
- 19:15Speaker 2: and email. Is this email spam or not spam, right,
- 19:17Speaker 2: But it's used for much more automatically organizing huge archives
- 19:21Speaker 2: of documents by topic, maybe trying to determine the authorship
- 19:24Speaker 2: of historical texts. There is famous work on the Federalist
- 19:28Speaker 2: papers using this cool or even trying to infer things
- 19:31Speaker 2: like the author's age range or gender based on writing style.
- 19:35Speaker 1: Interesting, okay. And sentiment analysis that's the positive negative thing.
- 19:39Speaker 3: Yes.
- 19:39Speaker 2: Sentiment analysis is a specific type of text classification focused
- 19:43Speaker 2: on determining the emotional tone or attitude expressed in a
- 19:46Speaker 2: piece of text. Is it positive, negative, neutral? Sometimes it's
- 19:51Speaker 2: mapped to a numerical writing like stars out of five?
- 19:53Speaker 1: Where do you apply that? Reviews, social media.
- 19:57Speaker 2: All of the above, product reviews, movie reroofm social media comments,
- 20:01Speaker 2: survey responses, anything where you want to gauge opinion. It
- 20:04Speaker 2: can be applied at different levels. The whole document, individual sentences,
- 20:08Speaker 2: even clauses within sentences.
- 20:10Speaker 1: Are their challenges. There it seems like it could be tricky, Oh,
- 20:13Speaker 1: very tricky.
- 20:14Speaker 2: One big challenge is that a single piece of text
- 20:16Speaker 2: can express different sentiments about different things, different.
- 20:19Speaker 3: Targets or attributes.
- 20:20Speaker 2: Think about a review like the ride was very rough,
- 20:23Speaker 2: but the attendants did an excellent job of making us comfortable.
- 20:27Speaker 1: Right, negative about the ride, positives about.
- 20:29Speaker 2: The stat exactly. The system needs to figure that out.
- 20:31Speaker 2: It's not just one overall sentiment sarcasm, irony, negation. They
- 20:36Speaker 2: all make it hard too.
- 20:37Speaker 1: How do they approach it?
- 20:39Speaker 2: Often they use sentiment lexicons. These are basically dictionaries where
- 20:43Speaker 2: words are pre scored with positive or negative sentiment values.
- 20:47Speaker 2: Examples include the General Inquirer or the MPQA Subjectivity ques lexicon.
- 20:53Speaker 2: You can essentially count up the positive.
- 20:55Speaker 3: And negative words.
- 20:56Speaker 1: How you build your own?
- 20:57Speaker 3: You can?
- 20:57Speaker 2: You can use semi supervised learning to techniques to build
- 21:00Speaker 2: a custom lexicon for your specific domain, which often works better.
- 21:04Speaker 1: Okay, And the last one was language identification right.
- 21:08Speaker 2: Language identification. This is usually simpler detecting which natural language
- 21:13Speaker 2: a piece of text is written in? Is it English, French, Spanish?
- 21:16Speaker 3: Japanese.
- 21:17Speaker 2: Tools like Linpipe have models trained on large multi lingual
- 21:21Speaker 2: data sets like the Leipzig Corporate.
- 21:23Speaker 1: Collection to do this. When would that be hard?
- 21:26Speaker 2: It gets tricky with very short texts like tweets, or
- 21:29Speaker 2: when a single text mixes multiple languages.
- 21:31Speaker 1: Yeah, I can see that, Okay, stepping back again, Yeah,
- 21:34Speaker 1: sometimes you don't just want to classify a document, You
- 21:37Speaker 1: want to know what it's about. More broadly, what are
- 21:39Speaker 1: the main themes in say a thousand news articles.
- 21:43Speaker 2: Ah, now you're talking about topic modeling.
- 21:45Speaker 1: Topic modeling exactly.
- 21:47Speaker 2: This is a set of techniques used to discover the
- 21:49Speaker 2: hidden abstract topics that occur in a collection of documents.
- 21:52Speaker 2: The idea is that each document can be represented as
- 21:55Speaker 2: a mixture of topics, and each topic is a distribution.
- 21:58Speaker 1: Over words, a mixture of topic.
- 22:00Speaker 2: Yeah, so an article might be seventy percent about politics,
- 22:03Speaker 2: twenty percent about economics, and ten percent about international relations.
- 22:08Speaker 2: Topic modeling helps find the relevance of each word across
- 22:11Speaker 2: the topics e g. Election vote are relevant to the
- 22:15Speaker 2: politics topic, and the relevance of the topics across each document.
- 22:18Speaker 1: How does it find those topics? They aren't labeled beforehand,
- 22:21Speaker 1: right right?
- 22:21Speaker 3: It's usually unsupervised.
- 22:23Speaker 2: A very popular method is latent diriclet allocation or LDA LDA.
- 22:28Speaker 2: LDA is a generative statistical model. Basically, it assumes a
- 22:31Speaker 2: process for how documents are created based on underlying topics,
- 22:34Speaker 2: and then it works backward from the observed documents the
- 22:37Speaker 2: words to infer the most likely topic structure that could
- 22:40Speaker 2: have generated them. It typically involves converting the text into
- 22:43Speaker 2: a document term matrix and then using sampling methods to
- 22:46Speaker 2: estimate two key matrices, a document topic matrix and a
- 22:50Speaker 2: topic term.
- 22:50Speaker 1: Matrix, so it uncovers the hidden themes automatically. That sounds
- 22:55Speaker 1: incredibly powerful for exploring large data sets.
- 22:58Speaker 3: It really is.
- 22:59Speaker 2: It's great for understanding the main themes running through large
- 23:02Speaker 2: amounts of text without having to read everything.
- 23:04Speaker 1: Now we've talked a lot about words, context topics, but
- 23:07Speaker 1: how do computers really get at the structure of a sentence,
- 23:11Speaker 1: the relationships between words, how phrases fit together. This feels
- 23:15Speaker 1: like it's getting closer to genuine understanding.
- 23:18Speaker 3: You're right.
- 23:18Speaker 2: This is about digging into the grammatical structure. This is
- 23:21Speaker 2: the domain of parsing and relationship extraction.
- 23:24Speaker 1: Parsing like diagramming sentences.
- 23:26Speaker 2: In school, very similar idea Parsing or syntactic analysis is
- 23:31Speaker 2: the process of analyzing a string of symbols, in this case,
- 23:34Speaker 2: words and a sentence according to the rules of a
- 23:36Speaker 2: formal grammar. The output is often a parse tree, which
- 23:40Speaker 2: is a tree like structure showing how the sentence is organized,
- 23:44Speaker 2: how phrases are nested within each other.
- 23:46Speaker 1: Are they different kinds of parsing?
- 23:47Speaker 3: Yes.
- 23:48Speaker 2: Two main types are common Dependency parsing focuses on the
- 23:51Speaker 2: grammatical relationships between individual words. Which word modifies which other word.
- 23:56Speaker 2: For example, the verb governs the noun, object and adjective
- 23:59Speaker 2: modify a known phrase. Structure parsing or constituency parsing focuses
- 24:05Speaker 2: on breaking the sentence down into nested phrases or constituents
- 24:08Speaker 2: like noun phrases, verb phrases, propositional phrases.
- 24:11Speaker 1: And what do we need pars pres What are they
- 24:13Speaker 1: used for?
- 24:13Speaker 2: They're fundamental for many advanced NLP tasks. Information extraction pulling
- 24:18Speaker 2: specific facts from text, sophisticated grammar checking, high quality machine
- 24:22Speaker 2: translation often relies heavily on parsing the source and target languages.
- 24:27Speaker 1: Okay, and related to that, you mentioned coreference.
- 24:29Speaker 2: Before, right, coreference resolution. This is a crucial related task
- 24:33Speaker 2: figuring out when different expressions in a text all refer
- 24:36Speaker 2: back to the same person, place, or thing the same entity.
- 24:39Speaker 2: Remember the example, he the robber, saw him the policeman
- 24:42Speaker 2: in Boston. Resolving he to the robber and him to
- 24:45Speaker 2: the policeman is coreference resolution.
- 24:48Speaker 1: And understanding these relationships, the parsing and the coreference that
- 24:52Speaker 1: must be vital for things like answering questions. Right.
- 24:55Speaker 2: Absolutely, think about a question answering system. If you ask
- 24:58Speaker 2: who is the thirty second present of the United States?
- 25:01Speaker 2: The system needs to parse that question. It needs to
- 25:04Speaker 2: identify who as the thing being asked for is president
- 25:08Speaker 2: of as the relationship and the thirty second and the
- 25:11Speaker 2: United States as specifying the entity. Then it uses that
- 25:14Speaker 2: structured understanding to find the answer. Franklin D. Roosevelt parsing
- 25:18Speaker 2: and coreference are key.
- 25:19Speaker 1: Wow, so we've covered a huge amount of ground all
- 25:22Speaker 1: these intricate techniques. Let's maybe pull back a bit and
- 25:26Speaker 1: look at the bigger picture. How are these NLP models
- 25:29Speaker 1: actually developed and trained and put to use. It sounds
- 25:32Speaker 1: like a massive process.
- 25:33Speaker 2: It certainly can be, But there's a general workflow, a
- 25:35Speaker 2: process for how these models are typically built and deployed. First,
- 25:38Speaker 2: you identify the specific task you need to solve, sentiment analysis,
- 25:42Speaker 2: any R translation, whatever it is. Then you select an
- 25:45Speaker 2: appropriate model or algorithm for that task. Then comes the
- 25:48Speaker 2: crucial part, building and door training the model. This nearly
- 25:53Speaker 2: always requires data, specifically a corpus that large collection of
- 25:57Speaker 2: text often marked up or annotates with the correct answers
- 26:01Speaker 2: for your.
- 26:01Speaker 1: Task, right the training data exactly.
- 26:03Speaker 2: You train the model on this data, then you need
- 26:06Speaker 2: to verify its quality test how well it performs, usually
- 26:09Speaker 2: on a separate sample set of data it hasn't seen before.
- 26:12Speaker 1: Check your work.
- 26:13Speaker 2: Precisely, and once you're satisfied with the quality, you can
- 26:16Speaker 2: finally apply the model to your real world problem, to
- 26:20Speaker 2: new unseen data. But even before all that, a critical
- 26:24Speaker 2: first step in almost any NLP project is preparing the data.
- 26:27Speaker 1: Ah. Data prep always important.
- 26:29Speaker 2: Crucial, finding the right data, getting it into a usable format,
- 26:33Speaker 2: and very importantly making sure it's clean. As we said,
- 26:37Speaker 2: many nlpapis and tools just assume the input data is
- 26:40Speaker 2: already cleaned up in consistent lowercase punctuation, handled, etc.
- 26:43Speaker 1: So cleaning is key. What about tools for this you
- 26:45Speaker 1: mentioned Java earlier.
- 26:47Speaker 2: Yeah, the source text focuses on Java. Java has pretty
- 26:49Speaker 2: good built in support for character processing, reading files, and
- 26:53Speaker 2: there are libraries for handling all sorts of formats you
- 26:55Speaker 2: might encounter HTML, Microsoft word documents, PDFSXML.
- 27:00Speaker 1: Well, so you can pull text out of those definitely.
- 27:02Speaker 2: And when it comes to the NLP tools themselves, especially
- 27:05Speaker 2: in the Java world, there are several major players. Patchy
- 27:08Speaker 2: Open NLP is a popular toolkit. The Stanford NLP group
- 27:12Speaker 2: provides a very comprehensive suite of tools. Ling Pipe is
- 27:15Speaker 2: another powerful option for search, specifically a patche Lucine Core
- 27:20Speaker 2: is a fantastic open source library for building text search engines.
- 27:23Speaker 2: It underlies things like elastic search and solar and it
- 27:26Speaker 2: relies heavily on NLP concepts like tokenization for indexing Lucine Yeah,
- 27:31Speaker 2: I heard of that, and of course for the really
- 27:33Speaker 2: cutting edge stuff. Deep learning libraries like deep Learning FOURG
- 27:36Speaker 2: deal FOURJ integrate NLP capabilities. Another really core concept often
- 27:41Speaker 2: tied closely to NLP, especially search, is information retrieval.
- 27:45Speaker 1: Or r R. How is that different from NLP?
- 27:48Speaker 2: They're very related, often overlap. IR is specifically focused on
- 27:53Speaker 2: finding relevant information within large collections of unstructured data data
- 27:58Speaker 2: without a predefined model. Text documents or web pages. Search
- 28:02Speaker 2: engines are the classic IR application.
- 28:04Speaker 1: How do they search so fast?
- 28:06Speaker 2: A key technique is using inverted indexes. Instead of storing
- 28:10Speaker 2: documents and searching through them, an inverted index maps each
- 28:14Speaker 2: term word to a list of documents where it appears,
- 28:17Speaker 2: and often its position within those.
- 28:19Speaker 1: Documents, like the index in the back of a book,
- 28:22Speaker 1: but for every word exactly.
- 28:24Speaker 3: It makes look ups much faster.
- 28:26Speaker 2: IR also deals with things like how to efficiently store
- 28:28Speaker 2: the vocabulary the dictionary of terms using structures like hash
- 28:32Speaker 2: tables or trees, and it needs tolerant retrieval. Tolerant retrieval
- 28:36Speaker 2: meaning it can handle things like typos or spelling variations.
- 28:39Speaker 2: This involves spelling correction, finding the nearest correct word to
- 28:43Speaker 2: a misspelled query term, maybe using edit distance or phonetic matching.
- 28:47Speaker 2: Algorithms like soundex and IR systems need to rank the
- 28:50Speaker 2: documents they find. This often involves the vector space model,
- 28:55Speaker 2: where documents and queries are represented as vectors and scoring
- 28:58Speaker 2: and term waiting, which brings us right back to good
- 29:01Speaker 2: old TFIDF for figuring out which documents are most relevant.
- 29:04Speaker 1: To the query. It all connects back, it really does.
- 29:07Speaker 1: Now you mentioned pipelines earlier. It's clear these components are
- 29:11Speaker 1: powerful on their own, but the real magic must be
- 29:14Speaker 1: when they work together. How are these individual pieces actually
- 29:18Speaker 1: assembled into a working system.
- 29:19Speaker 2: That's exactly right. It's done using combined pipelines. A pipeline
- 29:23Speaker 2: in this context is just that sequence of operations we
- 29:26Speaker 2: talked about. The output from one NLP step, say tokenization
- 29:30Speaker 2: becomes the input for the next step maybe pos, tagging yeah,
- 29:33Speaker 2: and its output feeds the next like any.
- 29:35Speaker 1: R, like an assembly line for text.
- 29:37Speaker 2: Analysis perfect analogy and tools are often designed with this
- 29:41Speaker 2: in mind. The Stanford core NLP library, for instance, is
- 29:44Speaker 2: built around this idea. It uses annotator objects for each
- 29:47Speaker 2: task token I, sentence split pos, tag, limitize, ANYR parse coreference.
- 29:52Speaker 2: You can easily define a pipeline specifying which annotators you
- 29:56Speaker 2: want to run.
- 29:57Speaker 3: In what order.
- 29:57Speaker 1: That seems really flexible it is.
- 30:00Speaker 2: These pipelines often start even before the core NLP tasks.
- 30:03Speaker 2: They might include initial steps for just getting the text
- 30:06Speaker 2: out of various formats. There are libraries like boiler pipe
- 30:10Speaker 2: specifically designed to extract the main text content from MESSYHTML
- 30:14Speaker 2: web pages, stripping out ads and menus oh useful, or
- 30:17Speaker 2: apatche poi for pulling text from Microsoft word files, or
- 30:21Speaker 2: apatche Tika for handling PDFs and a huge range of
- 30:23Speaker 2: other formats. Tika is amazing, actually, it can detect and
- 30:27Speaker 2: extract metadata and text from thousands of different types of files,
- 30:31Speaker 2: so it provides that clean text input needed to start
- 30:34Speaker 2: the main NLP pipeline.
- 30:35Speaker 1: Okay, that paints a much clearer picture of how it
- 30:38Speaker 1: all fits together. We've gone through a lot of complex components.
- 30:42Speaker 1: How does this all come together to create something tangible,
- 30:45Speaker 1: something maybe you and I interact with regularly. Let's connect
- 30:48Speaker 1: these techniques to a really common modern application. Chatbots. Ah.
- 30:55Speaker 2: Chatbots, yes, a perfect example of NLP in action have
- 31:00Speaker 2: absolutely exploded in popularity, haven't.
- 31:03Speaker 1: They Definitely on websites, in apps, voice assistance.
- 31:06Speaker 2: Exactly, Facebook Messengers, slack bots, Amazon Alexa, Google Assistant, Siri,
- 31:11Speaker 2: They're everywhere, and they've evolved quite a bit, from very
- 31:14Speaker 2: simple systems that just answered predefined questions to more sophisticated,
- 31:19Speaker 2: action oriented bots that can actually do things for you,
- 31:22Speaker 2: book appointments, place orders, provide detailed support.
- 31:25Speaker 1: So how do they work underneath? What's the architecture?
- 31:28Speaker 3: Well, you can think about a spectrum.
- 31:29Speaker 2: On one end, you have simple chatbots, maybe just following
- 31:32Speaker 2: a strict script or decision tree. Then you have more
- 31:34Speaker 2: conversational chatbots that can maintain contexts across several turns of
- 31:38Speaker 2: the dialogue. They remember what you said earlier. And then
- 31:41Speaker 2: you have the more advanced AI chatbots These often use
- 31:44Speaker 2: machine learning, learning from vast amounts of training conversations. These
- 31:48Speaker 2: AI bots heavily leverage the NLP techniques we've discussed. They
- 31:52Speaker 2: use natural language understanding NLU, which involves intent classifications and
- 31:58Speaker 2: figuring out what the user wants to do. When you
- 32:01Speaker 2: say to Alexa, set a timer for five minutes, the
- 32:03Speaker 2: intent is set a timer, got it? And they use
- 32:07Speaker 2: entity extraction pulling out the key pieces of information in
- 32:10Speaker 2: that example, five minutes.
- 32:12Speaker 1: Is the time entity.
- 32:14Speaker 2: Exactly, So a modern AI chatbot is essentially running a
- 32:17Speaker 2: complex NLP pipeline, understand the user's utterance NLU, decide what
- 32:23Speaker 2: to do, maybe query a database or API, and then
- 32:26Speaker 2: generate a natural language response NLG natural language generation.
- 32:29Speaker 1: That makes sense. What about simpler bots? Though not all
- 32:32Speaker 1: of them are full AI, right.
- 32:34Speaker 3: No, definitely not.
- 32:35Speaker 2: Many useful chat bots, especially for specific tasks, are retrieval
- 32:39Speaker 2: based models. These don't generate novel sentences, but select the
- 32:42Speaker 2: best response from a pre defined set, often using rules, templates,
- 32:46Speaker 2: and the conversation history context.
- 32:48Speaker 1: Okay, like picking the best canned.
- 32:50Speaker 2: Response kind of, but it can be quite sophisticated. One
- 32:54Speaker 2: common way to define the patterns and responses for these
- 32:56Speaker 2: bots is using Artificial Intelligence Markup Language or AML.
- 33:01Speaker 1: AML.
- 33:02Speaker 2: Yeah, it's an XML based language specifically designed for creating chatbots.
- 33:06Speaker 2: You define patterns the box should recognize, and the corresponding
- 33:09Speaker 2: templates for its response. So a very simple AML rule
- 33:12Speaker 2: might look like, if the user input pattern is hello,
- 33:15Speaker 2: the template responses hello, how.
- 33:18Speaker 1: Are you okay? Basic pattern matching.
- 33:20Speaker 2: It gets more powerful. You can use wild cards like
- 33:23Speaker 2: a pattern I like the star matches any word or phrase.
- 33:27Speaker 2: The response template could be okay, so you like star.
- 33:30Speaker 2: The star tag inserts whatever the user actually.
- 33:32Speaker 1: Set after I like clever, so it can echo back
- 33:35Speaker 1: part of the user's input yep.
- 33:37Speaker 2: And AML also has tags like set and get that
- 33:40Speaker 2: let the bot store and retrieve information within the conversation.
- 33:43Speaker 2: It can remember your name, for instance, using set, and
- 33:46Speaker 2: then use it later with get. That helps maintain context.
- 33:49Speaker 1: So even simpler chatbots use these structured ways to manage
- 33:52Speaker 1: dialogue exactly.
- 33:54Speaker 2: It provides a framework for building reasonably interactive conversational flows
- 33:58Speaker 2: without needing deep learning AI.
- 34:01Speaker 1: Okay, so let's wrap this up. What does this all
- 34:04Speaker 1: mean for us? You know, the people using this tech
- 34:08Speaker 1: every day. It feels like from deciphering single words and
- 34:11Speaker 1: their messy meanings, to understanding complex sentences, finding topics in
- 34:15Speaker 1: mountains of text, and even building these interactive chatbots. NLP
- 34:20Speaker 1: is just fundamentally changing how we interact with computers and information.
- 34:24Speaker 3: It absolutely is.
- 34:25Speaker 2: The progress has been stunning, especially in the last decade
- 34:28Speaker 2: or so.
- 34:28Speaker 1: It's really incredible to see how far it's.
- 34:30Speaker 2: Come, which really leaves us with a well, a pretty
- 34:33Speaker 2: fascinating question to think about, doesn't it. Given how much
- 34:36Speaker 2: of our own language, its subjectivity, its ambiguity, its reliance
- 34:40Speaker 2: on shared context remains challenging even for us humans. How
- 34:44Speaker 2: much further can computers really go? Can they move beyond
- 34:47Speaker 2: just processing language to truly understanding it with all its
- 34:50Speaker 2: nuance and implicit meaning? And if they can, or as
- 34:53Speaker 2: they get closer, what kinds of new applications might emerge?
- 34:57Speaker 2: How might our relationship with technology change? And more as
- 35:01Speaker 2: these tools become even more sophisticated at grasping the real
- 35:04Speaker 2: depth of human intention.
- 35:05Speaker 1: Wow, that's definitely something that you want. What is the
- 35:08Speaker 1: limit of machine understanding of something so fundamentally human as language?
- 35:12Speaker 2: Exactly the possibilities and perhaps the challenges seem genuinely boundless.