Update layout and content - #115
Conversation
- Include literature as references and create automated reference list in chapters - Improve layout: nicer colours, clearly distinguish between code chunks and code output by using different styles - Adjust header and footer Co-Authored-By: Claude <claude@users.noreply.github.com>
|
The target branch of this PR should be |
koheiw
left a comment
There was a problem hiding this comment.
Looks good overall except the themes. Comments are all minor points.
| print(toks_nopunct) | ||
| ``` | ||
|
|
||
| Compare the two tokens objects above: `toks_immig` still contains punctuation marks as separate tokens, while `toks_nopunct` does not, which is usually what you want before counting words. Removing punctuation and numbers at the tokenisation stage, rather than afterwards, is both faster and less error-prone than trying to strip them out later. |
There was a problem hiding this comment.
Internally, tokens_remove() is used after tokenization.
|
|
||
| `what = "word"`, the default you have been using so far, is not a single fixed set of rules, but tracks whichever version of **quanteda**'s built-in word tokenizer is current, set by `quanteda_options("tokens_tokenizer_word")`. That mapping has changed as the package has evolved. For most everyday work this is exactly what you want, since the current tokenizer is also the most accurate one. But it means the same code, `tokens(x)`, can silently produce different tokens after you or a collaborator updates **quanteda**. | ||
|
|
||
| `tokens()` also accepts several older, explicitly named versions of the tokenizer, so you can pin down and reproduce a specific rule set rather than relying on whichever version happens to be current. `"word1"` reproduces the pre-version-2 behaviour, `"word2"` and `"word3"` reproduce the versions used in **quanteda** 2 and 3, and `"word4"`, current at the time of writing, is what `what = "word"` currently maps onto. |
There was a problem hiding this comment.
Be more specific about the version of the package than saying "at the time of writing".
|
|
||
| ## Inspecting the structure of a tokens object | ||
|
|
||
| A tokens object is, underneath its printed display, a list with one element per document, each holding a character vector of that document's tokens in order. Converting it with `as.list()` makes this structure explicit, useful early on for building an accurate mental model of what a tokens object contains. |
There was a problem hiding this comment.
tokens object is a list of integer vectors.
| draft: false | ||
| --- | ||
|
|
||
| Many terms that matter in social scientific research are not single words but fixed phrases, such as "asylum seeker" or "climate change". If you tokenise text, by default `tokens()` splits these phrases into their separate parts, so "asylum" and "seeker" become two unrelated tokens rather than one meaningful unit. |
There was a problem hiding this comment.
independent tokens instead of unrelated?
| ``` | ||
|
|
||
| To preserve these expressions in a bag-of-word analysis, you have to compound them using `tokens_compound()`. | ||
| Most later analyses, including a document-feature matrix, only count individual tokens and have no way of knowing that two adjacent words belong together. To preserve multi-word expressions like these in that kind of "bag-of-words" analysis, you need to glue them together into a single token first, using `tokens_compound()`. As with `kwic()` in the [previous chapter](/basic-operations/tokens/kwic), `tokens_compound()` only recognises a pattern as a multi-word phrase if you wrap it in `phrase()`. Without it, "asylum seeker" is treated as one long, literal pattern that never matches anything, so the function silently compounds nothing, rather than raising an error. |
There was a problem hiding this comment.
Do you need "that kind of "?
There was a problem hiding this comment.
Please move the changes in layout to separate branch and revert. Applies to all the files under /static and /layouts.
| corp <- corpus_reshape(data_corpus_udhr["cmn_hans"], to = "paragraphs") | ||
| toks <- tokens(corp, remove_punct = TRUE, remove_numbers = TRUE) %>% | ||
| tokens_remove(pattern = stopwords("zh_cn", source = "marimo"), min_nchar = 2) %>% | ||
| toks <- tokens(corp, remove_punct = TRUE, remove_numbers = TRUE) |> |
There was a problem hiding this comment.
Good to set concatenator = '' in tokens() in Japanese and Chinese.
| tokens_remove(pattern = stopwords("ja", source = "marimo"), padding = TRUE) %>% | ||
| toks <- tokens(corp, remove_punct = TRUE, remove_numbers = TRUE, padding = TRUE) |> | ||
| tokens_remove(pattern = stopwords("ja", source = "marimo"), padding = TRUE) |> | ||
| tokens_select(pattern = "^[ぁ-んァ-ヶー一-龠]+$", valuetype = "regex", padding = TRUE) |
There was a problem hiding this comment.
Good to set concatenator = '' in tokens() in Japanese and Chinese.
| ```{r} | ||
| # compound collocations | ||
| toks_comp <- tokens_compound(toks, tstat_col[tstat_col$z > 3,], concatenator = "") %>% | ||
| toks_comp <- tokens_compound(toks, tstat_col[tstat_col$z > 3,], concatenator = "") |> |
There was a problem hiding this comment.
If we set concatenator = "" in tokens(), unnecessary.
| theme_set(theme_bw(base_size = 16)) | ||
| ``` | ||
|
|
||
| `textmodel_ca()` provides similar functionality to the standalone **ca** package, but the version in **quanteda.textmodels** works directly from a document-feature matrix, so you do not need to build a contingency table by hand first. We return to the Irish budget speeches used for Wordfish in the [previous chapter](/machine-learning/wordfish), so you can compare how the two methods position the same documents. |
There was a problem hiding this comment.
I don't think ca works with sparse matrices like DFM.
"directly with" instead of "directly from?
Content changes
Technical changes
Note: an initial, at times incomplete, draft of the new explanatory text was generated by @claude Code. I then substantively revised and edited this text.