Describe how natural language processing works and what it is used for.
The idea
Natural language processing turns unstructured text into numbers a model can use. Typical preparation lower-cases the text, splits it into tokens, removes stop words such as the and of, and reduces words to a stem or lemma. The cleaned text is then converted to features. One example is a bag-of-words count of each term. Another is a TF-IDF weight, which scales a term frequency by how rare the term is across documents. Models then classify or score the documents. Uses in finance include sentiment scoring of news and earnings calls, reading central bank statements, extracting risk disclosures from filings, and chatbots. Standard weaknesses are negation, sarcasm, and word lists written for general language that misread financial vocabulary. Domain-specific dictionaries and context-aware models help.
Formulas
TF-IDF weight of a term in a document
TF-IDF = TF × ln(N ÷ df)
- TF
- the term's count divided by the number of words in the document
- N
- the number of documents in the corpus
- df
- the number of documents containing the term
A term that appears in every document gets a weight of zero, which is the point: common words carry no information.
A practice question
What is the central task of natural language processing in finance?
- To forecast interest rates directly from regression of rates on their lags.Why not: Describes a time-series regression, not text processing.
- To standardise numerical data to mean 0 and standard deviation 1.Why not: Describes feature scaling, a data-preparation step rather than NLP.
- To convert unstructured text into numeric features that models can analyse. - correct
- To group numerical observations into K clusters.Why not: This is K-means clustering.
NLP preprocesses and encodes text (tokens, counts, TF-IDF weights, embeddings) so classification, sentiment or other analyses can be run.
A harder one
The sentence 'profit rose as profit margins improved and costs fell' is lower-cased, tokenised and cleaned by removing the stop words 'as' and 'and'. How many tokens remain?
- 9Why not: Counts the original tokens without removing stop words.
- 6Why not: Counts distinct words (profit appears twice) rather than tokens.
- 8Why not: Removes only one of the stop words.
- 7 - correct
Original tokens: profit, rose, as, profit, margins, improved, and, costs, fell = 9. Removing 'as' and 'and' leaves 7 tokens.
The hardest tier
A corpus has 1,000 filings. The term default appears in 50 of them. In one filing of 400 words it appears 8 times. Define term frequency as count divided by words in the filing, inverse document frequency as the natural log of (documents / documents containing the term), and TF-IDF as their product. What is the TF-IDF of default in that filing?
- 0.020Why not: Reports the term frequency only, ignoring the IDF weight.
- 0.026Why not: Uses a base-10 logarithm for IDF instead of the natural log.
- 0.060 - correct
- 23.97Why not: Multiplies the raw count of 8 by IDF instead of the term frequency.
TF = 8 / 400 = 0.02; IDF = ln(1000 / 50) = ln(20) = 2.996; TF-IDF = 0.02 x 2.996 = 0.060.
In the app: 6 practice questions on this outcome, spaced review that brings it back before you forget it.
Start free →More in Machine-Learning Methods
- Discuss how machine-learning techniques differ from classical econometrics in both philosophy and practice.
- Compare the two methods used to rescale variables when preparing data, and apply them.
- Explain what the training, validation and test sub-samples are, and the distinct purpose each serves.
- Examine how underfitting and overfitting differ and what follows from each, and outline possible remedies for both.
- Use principal components analysis to compress a set of features into fewer dimensions, and explain why that works.
- Outline how K-means assigns the observations in a sample to separate clusters.
- Distinguish unsupervised learning models from supervised ones and from reinforcement learning models.
- Describe the operation of reinforcement learning and calculate the Q-values used when making decisions.