\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{cheatingcvrlo} \pdfinfo{ /Title (is450.pdf) /Creator (Cheatography) /Author (cheatingcvrlo) /Subject (is450 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{is450 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{cheatingcvrlo} via \textcolor{DarkBackground}{\uline{cheatography.com/183658/cs/38238/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}cheatingcvrlo \\ \uline{cheatography.com/cheatingcvrlo} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 16th April, 2023.\\ Updated 17th April, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{preprocessing pipeline}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\{lang-python\}\}def corpus2docs(corpus): \newline fids = corpus.fileids() \newline docs1 = {[}{]} \newline for fid in fids: \newline doc\_raw = corpus.raw(fid) \newline doc = \seqsplit{nltk.word\_tokenize(doc\_raw)} \newline docs1.append(doc) \newline docs2 = {[}{[}w.lower() for w in doc{]} for doc in docs1{]} \newline docs3 = {[}{[}w for w in doc if re.search('\textasciicircum{}{[}a-z{]}+\$', w){]} for doc in docs2{]} \newline docs4 = {[}{[}w for w in doc if w not in stop\_list{]} for doc in docs3{]} \newline docs5 = {[}{[}stemmer.stem(w) for w in doc{]} for doc in docs4{]} \newline return docs5 \newline \newline def docs2vecs(docs, dictionary): \newline \# docs is a list of documents returned by corpus2docs. \newline \# dictionary is a \seqsplit{gensim.corpora.Dictionary} object. \newline vecs1 = {[}dictionary.doc2bow(doc) for doc in docs{]} \newline tfidf = \seqsplit{gensim.models.TfidfModel(vecs1)} \newline vecs2 = {[}tfidf{[}vec{]} for vec in vecs1{]} \newline return vecs2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{POS tags}} \tn % Row 0 \SetRowColor{LightBackground} N (noun) & dog, cat, chair \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} V (verb) & read, write, get \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} ADJ (adjective) & pretty, smart, blue \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} ADV (adverb) & gently, carefully, extremely \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} P (preposition) & in, on, by, with, about \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} PRO (pronoun) & I, me, mine, it, they... \tn % Row Count 8 (+ 2) % Row 6 \SetRowColor{LightBackground} CON (conjunction) & and, or, but, while, because \tn % Row Count 10 (+ 2) % Row 7 \SetRowColor{white} INT (interjection) & ooh, wow, yeah \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} DET (determiner) & all, his, they \tn % Row Count 13 (+ 1) % Row 9 \SetRowColor{white} AUX (auxiliary verb) & {\bf{have}} done, {\bf{might}} do \tn % Row Count 15 (+ 2) % Row 10 \SetRowColor{LightBackground} PAR (particle) & look {\bf{up}}, get {\bf{on}} \tn % Row Count 16 (+ 1) % Row 11 \SetRowColor{white} NUM (numeral) & one, two, three \tn % Row Count 17 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Context-free grammar}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Grammar = \{ \newline objects: {[} \newline Words/tokens: {\bf{terminals}}, \newline Right above: {\bf{pos tags}}, \newline Above: {\bf{syntactic tags}}, \newline Above: {\bf{sentence}} \newline {]}; \newline Rules: {[} \newline X: node name, \#eg "VP" (verb phrase) \newline Y: sequence of objects that make up X \#eg (V+NP) \newline {]} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Morphemes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{stems, affixes (prefix/suffix). Useful for POS tagging and text normalization% Row Count 2 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.9908 cm} x{2.9862 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Semantics}} \tn % Row 0 \SetRowColor{LightBackground} synonyms & diff words, same meaning \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} polyseme & same word, diff meaning \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{hypernym/hyponym} & category \textgreater{}\textgreater{}\textgreater{} specific \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} meronym/metonym & part \textgreater{}\textgreater{}\textgreater{} whole \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{LDA}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681633865_lda.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{LDA}} \tn % Row 0 \SetRowColor{LightBackground} gibbs sampling & 1. random word-to-topic assignment \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & 2. re-assign each word to a topic, one by one, {\bf{assuming all other assignments are correct}} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{hyperparameters} & high \$alpha\$ -{}-\textgreater{} documents feature a mixture of most topics \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} & high \$eta\$ -{}-\textgreater{} topics feature a mixture of most words \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{evaluation} & coherence (PMI), human eval \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sentiment-Topic Model (Plate Notation)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681634916_jst.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Cluster Purity}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681633634_cluster_purity.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Overall purity}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681633564_purity.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Cluster Entropy}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681633787_cluster_entropy.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Pointwise Mutual Information}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{5.377cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/cheatingcvrlo_1681634733_pmi.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Discourse Markers}} \tn % Row 0 \SetRowColor{LightBackground} causal & because \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} consequence & as a result \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} conditional & if \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} temporal & when \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} additive & and \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} elaboration & {[}exemplification, re-wording{]} \tn % Row Count 7 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{contrastive/concessive} & but \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Preparation for NLTK classifier}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#doc\_tuple = (doc\_representation, label) \newline % Row Count 1 (+ 1) \textgreater{} `\{\{lang-python\}\}(\{'police':1, 'lawyer':1, 'court':1\}, 'Crime')` \newline % Row Count 3 (+ 2) \#train\_set = {[}doc\_tuple1, doc\_tuple2, ...{]}% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}