Words and Tokens
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 2
3 cards in “2.7 Simple Unix tools for word tokenization” · whole deck
2.7 Simple Unix tools for word tokenization
- What does
tr -sc 'A-Za-z' '\n' < sh.txtdo?Tokenizes naively:-ccomplements the set (all non-letters), which are changed to newlines, and-ssqueezes runs into a single newline, giving one word per line.- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 2, §2.7, pp. 56–57
- Write a Unix pipeline that lists the most frequent words in a text file, case-insensitively.
tr -sc 'A-Za-z' '\n' < f.txt | tr A-Z a-z | sort | uniq -c | sort -n -r- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 2, §2.7, p. 57
- What are the most frequent words in any corpus, Shakespeare included?Short function words: articles, pronouns, prepositions (the, and, i, to, of, a…).
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 2, §2.7, p. 58
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/