├── .gitignore ├── data ├── bbc │ ├── sport.csv.bz2 │ ├── tech.csv.bz2 │ ├── business.csv.bz2 │ ├── politics.csv.bz2 │ ├── entertainment.csv.bz2 │ └── README.TXT ├── munge-bbc.sh └── example.csv ├── img ├── bbc_pca_all_topics.png └── bbc_pca_business_sport.png ├── setup.sh ├── README.md ├── requirements.txt ├── doc2vec.py ├── LICENSE └── doc2vec.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | venv 3 | -------------------------------------------------------------------------------- /data/bbc/sport.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/data/bbc/sport.csv.bz2 -------------------------------------------------------------------------------- /data/bbc/tech.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/data/bbc/tech.csv.bz2 -------------------------------------------------------------------------------- /data/bbc/business.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/data/bbc/business.csv.bz2 -------------------------------------------------------------------------------- /data/bbc/politics.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/data/bbc/politics.csv.bz2 -------------------------------------------------------------------------------- /img/bbc_pca_all_topics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/img/bbc_pca_all_topics.png -------------------------------------------------------------------------------- /data/bbc/entertainment.csv.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/data/bbc/entertainment.csv.bz2 -------------------------------------------------------------------------------- /img/bbc_pca_business_sport.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbowdon/doc2vec-pytorch/HEAD/img/bbc_pca_business_sport.png -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | python3 -m venv venv && 4 | venv/bin/pip install --upgrade pip && 5 | venv/bin/pip install -r requirements.txt && 6 | venv/bin/python3 -m spacy download en_core_web_sm 7 | -------------------------------------------------------------------------------- /data/munge-bbc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Given the documents extracted from bbc-fulltext.zip... 4 | 5 | echo "Munging $1 files..." 6 | 7 | pushd "bbc/$1" 8 | 9 | for f in *.txt; do 10 | line_file="${f/.txt/.line}" 11 | printf '"' > "$line_file" 12 | cat --squeeze-blank "$f" | 13 | tr '\n' ' ' | 14 | tr '"' "'" >> "$line_file" 15 | printf '"\n' >> "$line_file" 16 | done 17 | 18 | echo 'text' > "../$1.csv" 19 | cat --squeeze-blank *.line >> "../$1.csv" 20 | 21 | rm *.line 22 | 23 | popd 24 | -------------------------------------------------------------------------------- /data/bbc/README.TXT: -------------------------------------------------------------------------------- 1 | Consists of 2225 documents from the BBC news website corresponding to stories in five topical areas from 2004-2005. 2 | Natural Classes: 5 (business, entertainment, politics, sport, tech) 3 | 4 | If you make use of the dataset, please consider citing the publication: 5 | - D. Greene and P. Cunningham. "Practical Solutions to the Problem of Diagonal Dominance in Kernel Document Clustering", Proc. ICML 2006. 6 | 7 | All rights, including copyright, in the content of the original articles are owned by the BBC. 8 | 9 | Contact Derek Greene for further information. 10 | http://mlg.ucd.ie/datasets/bbc.html 11 | 12 | -------------------------------------------------------------------------------- /data/example.csv: -------------------------------------------------------------------------------- 1 | text 2 | "In the week before their departure to Arrakis, when all the final scurrying about had reached a nearly unbearable frenzy, an old crone came to visit the mother of the boy, Paul." 3 | "It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreides family as home for twenty-six generations bore that cooled-sweat feeling it acquired before a change in the weather." 4 | "The old woman was let in by the side door down the vaulted passage by Paul's room and she was allowed a moment to peer in at him where he lay in his bed." 5 | "By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could see a bulky female shape at his door, standing one step ahead of his mother. The old woman was a witch shadow - hair like matted spiderwebs, hooded 'round darkness of features, eyes like glittering jewels." 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Doc2vec from scratch in PyTorch 2 | =============================== 3 | 4 | [This notebook](https://nbviewer.jupyter.org/github/cbowdon/doc2vec-pytorch/blob/master/doc2vec.ipynb) explains how to implement `doc2vec` using PyTorch. It's aimed at relative beginners, but basic understanding of word embeddings (vectors) and PyTorch are assumed. 5 | 6 | The implementation we end up with is hopefully correct but definitely not perfect. There's room for improvement in efficiency and features. Plus I have no intention of maintaining this, so please use a more established implementation for "serious" work. If you would like a PyTorch implementation, I recommend [this one](https://github.com/inejc/paragraph-vectors), from which this borrows extensively. 7 | 8 | _Visualization of the notebook model's results for the BBC dataset:_ 9 | 10 | ![](./img/bbc_pca_business_sport.png) 11 | 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | altair==2.4.1 2 | backcall==0.1.0 3 | bleach==3.1.0 4 | blis==0.2.4 5 | certifi==2019.3.9 6 | chardet==3.0.4 7 | cymem==2.0.2 8 | decorator==4.4.0 9 | defusedxml==0.6.0 10 | entrypoints==0.3 11 | idna==2.8 12 | ipykernel==5.1.0 13 | ipython==7.4.0 14 | ipython-genutils==0.2.0 15 | jedi==0.13.3 16 | Jinja2==2.10.1 17 | jsonschema==2.6.0 18 | jupyter-client==5.2.4 19 | jupyter-core==4.4.0 20 | jupyterlab==0.35.4 21 | jupyterlab-server==0.2.0 22 | MarkupSafe==1.1.1 23 | mistune==0.8.4 24 | murmurhash==1.0.2 25 | nbconvert==5.4.1 26 | nbformat==4.4.0 27 | notebook==5.7.8 28 | numpy==1.16.3 29 | pandas==0.24.2 30 | pandocfilters==1.4.2 31 | parso==0.4.0 32 | pexpect==4.7.0 33 | pickleshare==0.7.5 34 | plac==0.9.6 35 | preshed==2.0.1 36 | prometheus-client==0.6.0 37 | prompt-toolkit==2.0.9 38 | ptyprocess==0.6.0 39 | Pygments==2.3.1 40 | python-dateutil==2.8.0 41 | pytz==2019.1 42 | pyzmq==18.0.1 43 | requests==2.21.0 44 | scikit-learn==0.20.3 45 | scipy==1.2.1 46 | Send2Trash==1.5.0 47 | six==1.12.0 48 | sklearn==0.0 49 | spacy==2.1.3 50 | srsly==0.0.5 51 | terminado==0.8.2 52 | testpath==0.4.2 53 | thinc==7.0.4 54 | toolz==0.9.0 55 | torch==1.0.1.post2 56 | tornado==6.0.2 57 | tqdm==4.31.1 58 | traitlets==4.3.2 59 | urllib3==1.24.2 60 | wasabi==0.2.1 61 | wcwidth==0.1.7 62 | webencodings==0.5.1 63 | -------------------------------------------------------------------------------- /doc2vec.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # Doc2vec from scratch in PyTorch 5 | # =============================== 6 | # 7 | # Here we are implementing this useful algorithm with a library we know and trust. With luck this will be more accessible than reading the papers but more in-depth than typical "install gensim and just do what I say" tutorials, and still easy to understand for anyone whose maths skills have atrophied to nothing (like me). This is all based on the great work by [Nejc Ilenic](https://github.com/inejc/paragraph-vectors) and reading the referenced papers and gensim's source. 8 | # 9 | # `doc2vec` descends from `word2vec`, the basic form of which is that it is a model trained to predict the missing word in a context. Given sentences like "the cat ___ on the mat" it should predict "sat", and in doing so learn a useful representation of words. We can then extract the internal weights and re-use them as "word embeddings", vectors giving each word a position in N-dimensional space that is hopefully close to similar words and an appropriate distance from related words. 10 | # 11 | # `doc2vec` or "Paragraph vectors" extends the `word2vec` idea by simply adding a document id to each context. This helps the network learn associations between contexts and produces vectors that position each paragraph (document) in space. 12 | 13 | # First we need to load the data. We'll begin by overfitting on a tiny dataset just to check all the parts fit together. 14 | 15 | # In[1]: 16 | 17 | 18 | import pandas as pd 19 | import spacy 20 | 21 | nlp = spacy.load("en_core_web_sm") 22 | 23 | pd.set_option("display.max_colwidth", 100) 24 | 25 | example_df = pd.read_csv("data/example.csv") 26 | 27 | def tokenize_text(df): 28 | df["tokens"] = df.text.str.lower().str.strip().apply(lambda x: [token.text.strip() for token in nlp(x) if token.text.isalnum()]) 29 | return df 30 | 31 | example_df = tokenize_text(example_df) 32 | 33 | example_df 34 | 35 | 36 | # We will need to construct a vocabulary so we can reference every word by an ID. 37 | 38 | # In[2]: 39 | 40 | 41 | from collections import Counter 42 | 43 | class Vocab: 44 | def __init__(self, all_tokens, min_count=2): 45 | self.min_count = min_count 46 | self.freqs = {t:n for t, n in Counter(all_tokens).items() if n >= min_count} 47 | self.words = sorted(self.freqs.keys()) 48 | self.word2idx = {w: i for i, w in enumerate(self.words)} 49 | 50 | vocab = Vocab([tok for tokens in example_df.tokens for tok in tokens], min_count=1) 51 | 52 | print(f"Dataset comprises {len(example_df)} documents and {len(vocab.words)} unique words (over the limit of {vocab.min_count} occurrences)") 53 | 54 | 55 | # Words that appear extremely rarely can harm performance, so we add a simple mechanism to strip those out. 56 | 57 | # In[3]: 58 | 59 | 60 | def clean_tokens(df, vocab): 61 | df["length"] = df.tokens.apply(len) 62 | df["clean_tokens"] = df.tokens.apply(lambda x: [t for t in x if t in vocab.freqs.keys()]) 63 | df["clean_length"] = df.clean_tokens.apply(len) 64 | return df 65 | 66 | example_df = clean_tokens(example_df, vocab) 67 | example_df[:5] 68 | 69 | 70 | # The difficulty with our "the cat _ on the mat" problem is that the missing word could be any one in the vocabulary V and so the network would have |V| outputs for each input e.g. a huge vector containing zero for every word in the vocabulary and some positive number for "sat" if the network was perfectly trained. For calculating loss we need to turn that into a probabilty distribution, i.e. _softmax_ it. Computing the softmax for such a large vector is expensive. 71 | # 72 | # So the trick (one of many possible) we will use is _Noise Contrastive Estimation (NCE)_. We change our "the cat _ on the mat" problem into a multiple choice problem, asking the network to choose between "sat" and some random wrong answers like "hopscotch" and "luxuriated". This is easier to compute the softmax for since it's now a binary classifier (right or wrong answer) and the output is simply of a vector of size 1 + k where k is the number of random incorrect options. 73 | # 74 | # Happily, this alternative problem still learns equally useful word representations. We just need to adjust the examples and the loss function. There is a simplified version of the NCE loss function called _Negative Sampling (NEG)_ that we can use here. 75 | # 76 | # [Notes on Noise Contrastive Estimation and Negative Sampling (C. Dyer)](https://arxiv.org/abs/1410.8251) explains the derivation of the NCE and NEG loss functions. 77 | # 78 | # When we implement the loss function, we assume that the first element in a samples/scores vector is the score for the positive sample and the rest are negative samples. This convention saves us from having to pass around an auxiliary vector indicating which sample was positive. 79 | 80 | # In[4]: 81 | 82 | 83 | import torch.nn as nn 84 | 85 | class NegativeSampling(nn.Module): 86 | def __init__(self): 87 | super(NegativeSampling, self).__init__() 88 | self.log_sigmoid = nn.LogSigmoid() 89 | def forward(self, scores): 90 | batch_size = scores.shape[0] 91 | n_negative_samples = scores.shape[1] - 1 # TODO average or sum the negative samples? Summing seems to be correct by the paper 92 | positive = self.log_sigmoid(scores[:,0]) 93 | negatives = torch.sum(self.log_sigmoid(-scores[:,1:]), dim=1) 94 | return -torch.sum(positive + negatives) / batch_size # average for batch 95 | 96 | loss = NegativeSampling() 97 | 98 | 99 | # It's helpful to play with some values to reassure ourselves that this function does the right thing. 100 | 101 | # In[5]: 102 | 103 | 104 | import torch 105 | 106 | data = [[[1, -1, -1, -1]], # this dummy data uses -1 to 1, but the real model is unconstrained 107 | [[0.5, -1, -1, -1]], 108 | [[0, -1, -1, -1]], 109 | [[0, 0, 0, 0]], 110 | [[0, 0, 0, 1]], 111 | [[0, 1, 1, 1]], 112 | [[0.5, 1, 1, 1]], 113 | [[1, 1, 1, 1]]] 114 | 115 | loss_df = pd.DataFrame(data, columns=["scores"]) 116 | loss_df["loss"] = loss_df.scores.apply(lambda x: loss(torch.FloatTensor([x]))) 117 | 118 | loss_df 119 | 120 | 121 | # Higher scores for the positive sample (always the first element) reduce the loss but higher scores for the negative samples increase the loss. This looks like the right behaviour. 122 | 123 | # With that in the bag, let's look at creating training data. The general idea is to create a set of examples where each example has: 124 | # 125 | # - doc id 126 | # - sample ids - a collection of the target token and some noise tokens 127 | # - context ids - tokens before and after the target token 128 | # 129 | # e.g. If our context size was 2, the first example from the above dataset would be: 130 | # 131 | # ``` 132 | # {"doc_id": 0, 133 | # "sample_ids": [word2idx[x] for x in ["week", "random-word-from-vocab", "random-word-from-vocab"...], 134 | # "context_ids": [word2idx[x] for x in ["in", "the", "before", "their"]]} 135 | # ``` 136 | # 137 | # The random words are chosen according to a probability distribution: 138 | # 139 | # > a unigram distribution raised to the 3/4rd power, as proposed by T. Mikolov et al. in Distributed Representations of Words and Phrases and their Compositionality 140 | # 141 | # This has the effect of slightly increasing the relative probability of rare words (look at the graph of `y=x^0.75` below and see how the lower end is raised above `y=x`). 142 | 143 | # In[6]: 144 | 145 | 146 | import altair as alt 147 | import numpy as np 148 | 149 | data = pd.DataFrame(zip(np.arange(0,1,0.01), np.power(np.arange(0,1,0.01), 0.75)), columns=["x", "y"]) 150 | alt.Chart(data, title="x^0.75").mark_line().encode(x="x", y="y") 151 | 152 | 153 | # In[7]: 154 | 155 | 156 | import numpy as np 157 | 158 | class NoiseDistribution: 159 | def __init__(self, vocab): 160 | self.probs = np.array([vocab.freqs[w] for w in vocab.words]) 161 | self.probs = np.power(self.probs, 0.75) 162 | self.probs /= np.sum(self.probs) 163 | def sample(self, n): 164 | "Returns the indices of n words randomly sampled from the vocabulary." 165 | return np.random.choice(a=self.probs.shape[0], size=n, p=self.probs) 166 | 167 | noise = NoiseDistribution(vocab) 168 | 169 | 170 | # With this distribution, we advance through the documents creating examples. Note that we are always putting the positive sample first in the samples vector, following the convention the loss function expects. 171 | 172 | # In[8]: 173 | 174 | 175 | import torch 176 | 177 | def example_generator(df, context_size, noise, n_negative_samples, vocab): 178 | for doc_id, doc in df.iterrows(): 179 | for i in range(context_size, len(doc.clean_tokens) - context_size): 180 | positive_sample = vocab.word2idx[doc.clean_tokens[i]] 181 | sample_ids = noise.sample(n_negative_samples).tolist() 182 | # Fix a wee bug - ensure negative samples don't accidentally include the positive 183 | sample_ids = [sample_id if sample_id != positive_sample else -1 for sample_id in sample_ids] 184 | sample_ids.insert(0, positive_sample) 185 | context = doc.clean_tokens[i - context_size:i] + doc.clean_tokens[i + 1:i + context_size + 1] 186 | context_ids = [vocab.word2idx[w] for w in context] 187 | yield {"doc_ids": torch.tensor(doc_id), # we use plural here because it will be batched 188 | "sample_ids": torch.tensor(sample_ids), 189 | "context_ids": torch.tensor(context_ids)} 190 | 191 | examples = example_generator(example_df, context_size=5, noise=noise, n_negative_samples=5, vocab=vocab) 192 | 193 | 194 | # Now we package this up as a good old PyTorch dataset and dataloader. 195 | 196 | # In[9]: 197 | 198 | 199 | from torch.utils.data import Dataset, DataLoader 200 | 201 | class NCEDataset(Dataset): 202 | def __init__(self, examples): 203 | self.examples = list(examples) # just naively evaluate the whole damn thing - suboptimal! 204 | def __len__(self): 205 | return len(self.examples) 206 | def __getitem__(self, index): 207 | return self.examples[index] 208 | 209 | dataset = NCEDataset(examples) 210 | dataloader = DataLoader(dataset, batch_size=2, drop_last=True, shuffle=True) # TODO bigger batch size when not dummy data 211 | 212 | 213 | # It's going to also be useful to have a way to convert batches back to a readable form for debugging, so we add a helper function. 214 | 215 | # In[10]: 216 | 217 | 218 | def describe_batch(batch, vocab): 219 | results = [] 220 | for doc_id, context_ids, sample_ids in zip(batch["doc_ids"], batch["context_ids"], batch["sample_ids"]): 221 | context = [vocab.words[i] for i in context_ids] 222 | context.insert(len(context_ids) // 2, "____") 223 | samples = [vocab.words[i] for i in sample_ids] 224 | result = {"doc_id": doc_id, 225 | "context": " ".join(context), 226 | "context_ids": context_ids, 227 | "samples": samples, 228 | "sample_ids": sample_ids} 229 | results.append(result) 230 | return results 231 | 232 | describe_batch(next(iter(dataloader)), vocab) 233 | 234 | 235 | # Let's jump into creating the model itself. There isn't much to it - we multiply the input paragraph and word matrices by the output layer. Combining the paragraph and word matrices is done by summing here, but it could also be done by concatenating the inputs. The original paper actually found concatenation works better, perhaps because summing loses word order information. 236 | 237 | # In[11]: 238 | 239 | 240 | import torch.nn as nn 241 | 242 | class DistributedMemory(nn.Module): 243 | def __init__(self, vec_dim, n_docs, n_words): 244 | super(DistributedMemory, self).__init__() 245 | self.paragraph_matrix = nn.Parameter(torch.randn(n_docs, vec_dim)) 246 | self.word_matrix = nn.Parameter(torch.randn(n_words, vec_dim)) 247 | self.outputs = nn.Parameter(torch.zeros(vec_dim, n_words)) 248 | 249 | def forward(self, doc_ids, context_ids, sample_ids): 250 | # first add doc ids to context word ids to make the inputs 251 | inputs = torch.add(self.paragraph_matrix[doc_ids,:], # (batch_size, vec_dim) 252 | torch.sum(self.word_matrix[context_ids,:], dim=1)) # (batch_size, 2x context, vec_dim) -> sum to (batch_size, vec_dim) 253 | # 254 | # select the subset of the output layer for the NCE test 255 | outputs = self.outputs[:,sample_ids] # (vec_dim, batch_size, n_negative_samples + 1) 256 | # 257 | return torch.bmm(inputs.unsqueeze(dim=1), # then multiply with some munging to make the tensor shapes line up 258 | outputs.permute(1, 0, 2)).squeeze() # -> (batch_size, n_negative_samples + 1) 259 | 260 | model = DistributedMemory(vec_dim=50, 261 | n_docs=len(example_df), 262 | n_words=len(vocab.words)) 263 | 264 | 265 | # Let's take it for a spin! 266 | 267 | # In[12]: 268 | 269 | 270 | with torch.no_grad(): 271 | logits = model.forward(**next(iter(dataloader))) 272 | logits 273 | 274 | 275 | # Oh yeah, the output layer was initialized with zeros. Time to bash out a standard issue PyTorch training loop. 276 | 277 | # In[13]: 278 | 279 | 280 | from tqdm import tqdm, trange 281 | from torch.optim import Adam # ilenic uses Adam, but gensim uses plain SGD 282 | import numpy as np 283 | 284 | def train(model, dataloader, epochs=40, lr=1e-3): 285 | optimizer = Adam(model.parameters(), lr=lr) 286 | training_losses = [] 287 | try: 288 | for epoch in trange(epochs, desc="Epochs"): 289 | epoch_losses = [] 290 | for batch in dataloader: 291 | model.zero_grad() 292 | logits = model.forward(**batch) 293 | batch_loss = loss(logits) 294 | epoch_losses.append(batch_loss.item()) 295 | batch_loss.backward() 296 | optimizer.step() 297 | training_losses.append(np.mean(epoch_losses)) 298 | except KeyboardInterrupt: 299 | print(f"Interrupted on epoch {epoch}!") 300 | finally: 301 | return training_losses 302 | 303 | 304 | # Now we'll sanity check by overfitting the example data. Training loss should drop from untrained loss to something close to the minimum possible. 305 | 306 | # In[14]: 307 | 308 | 309 | training_losses = train(model, dataloader, epochs=40, lr=1e-3) 310 | 311 | 312 | # In[15]: 313 | 314 | 315 | import altair as alt 316 | 317 | df_loss = pd.DataFrame(enumerate(training_losses), columns=["epoch", "training_loss"]) 318 | alt.Chart(df_loss).mark_bar().encode(alt.X("epoch"), alt.Y("training_loss", scale=alt.Scale(type="log"))) 319 | 320 | 321 | # And because we're paranoid types, let's check a prediction. 322 | 323 | # In[16]: 324 | 325 | 326 | with torch.no_grad(): 327 | logits = model.forward(**next(iter(dataloader))) 328 | logits 329 | 330 | 331 | # The positive sample gets a positive score and the negatives get negative scores. Super. 332 | 333 | # We should be able get the paragraph vectors for the documents and do things like check these for similarity to one another. 334 | 335 | # In[17]: 336 | 337 | 338 | from sklearn.preprocessing import normalize 339 | 340 | def most_similar(paragraph_matrix, docs_df, index, n=None): 341 | pm = normalize(paragraph_matrix, norm="l2") # in a smarter implementation we would cache this somewhere 342 | sims = np.dot(pm, pm[index,:]) 343 | df = pd.DataFrame(enumerate(sims), columns=["doc_id", "similarity"]) 344 | n = n if n is not None else len(sims) 345 | return df.merge(docs_df[["text"]].reset_index(drop=True), left_index=True, right_index=True).sort_values(by="similarity", ascending=False)[:n] 346 | 347 | most_similar(model.paragraph_matrix.data, example_df, 1, n=10) 348 | 349 | 350 | # It's not particularly illuminating for our tiny set of dummy data though. We can also use PCA to reduce our n-dimensional paragraph vectors to 2 dimensions and see if they are clustered nicely. 351 | 352 | # In[18]: 353 | 354 | 355 | from sklearn.decomposition import PCA 356 | 357 | def pca_2d(paragraph_matrix, groups): 358 | pca = PCA(n_components=2) 359 | reduced_dims = pca.fit_transform(paragraph_matrix) 360 | print(f"2-component PCA, explains {sum(pca.explained_variance_):.2f}% of variance") 361 | df = pd.DataFrame(reduced_dims, columns=["x", "y"]) 362 | df["group"] = groups 363 | return df 364 | 365 | example_2d = pca_2d(model.paragraph_matrix.data, ["0","1","2","3"]) 366 | alt.Chart(example_2d).mark_point().encode(x="x", y="y", color="group") 367 | 368 | 369 | # Not much to see on such a tiny dataset without any labelled groups. 370 | 371 | # Running this on some bigger data 372 | # -------------------------------- 373 | # 374 | # We'll use the BBC's dataset. The dataset was created by Derek Greene at UCD and all articles are copyright Auntie. I've munged it into a file per topic. 375 | 376 | # In[19]: 377 | 378 | 379 | dfs = [] 380 | for document_set in ("sport", 381 | "business", 382 | "politics", 383 | "tech", 384 | "entertainment"): 385 | df_ = pd.read_csv(f"data/bbc/{document_set}.csv.bz2", encoding="latin1") 386 | df_ = tokenize_text(df_) 387 | df_["group"] = document_set 388 | dfs.append(df_) 389 | 390 | bbc_df = pd.concat(dfs) 391 | bbc_df[:4] 392 | 393 | 394 | # In[20]: 395 | 396 | 397 | bbc_vocab = Vocab([tok for tokens in bbc_df.tokens for tok in tokens]) 398 | 399 | bbc_df = clean_tokens(bbc_df, bbc_vocab) 400 | 401 | print(f"Dataset comprises {len(bbc_df)} documents and {len(bbc_vocab.words)} unique words") 402 | 403 | 404 | # In[21]: 405 | 406 | 407 | bbc_noise = NoiseDistribution(bbc_vocab) 408 | bbc_examples = list(example_generator(bbc_df, context_size=5, noise=bbc_noise, n_negative_samples=5, vocab=bbc_vocab)) 409 | 410 | 411 | # In[22]: 412 | 413 | 414 | bbc_dataset = NCEDataset(bbc_examples) 415 | bbc_dataloader = DataLoader(bbc_dataset, batch_size=1024, drop_last=True, shuffle=True) # TODO could tolerate a larger batch size 416 | 417 | bbc_model = DistributedMemory(vec_dim=50, 418 | n_docs=len(bbc_df), 419 | n_words=len(bbc_vocab.words)) 420 | 421 | 422 | # In[23]: 423 | 424 | 425 | bbc_training_losses = train(bbc_model, bbc_dataloader, epochs=80, lr=1e-3) 426 | 427 | 428 | # In[24]: 429 | 430 | 431 | alt.Chart(pd.DataFrame(enumerate(bbc_training_losses), columns=["epoch", "training_loss"])).mark_bar().encode(x="epoch", y="training_loss") 432 | 433 | 434 | # Let's take a look at the reduced dimensionality paragraph vectors. 435 | 436 | # In[ ]: 437 | 438 | 439 | bbc_2d = pca_2d(bbc_model.paragraph_matrix.data, bbc_df.group.to_numpy()) 440 | chart = alt.Chart(bbc_2d).mark_point().encode(x="x", y="y", color="group") 441 | # Uncomment to print chart inline, but beware it will inflate the notebook size 442 | # chart 443 | 444 | 445 | # `2-component PCA, explains 2.65% of variance` 446 | # 447 | # ![](./img/bbc_pca_all_topics.png) 448 | 449 | # These results aren't great, but we can see the beginnings of separation. If we look at just two topics it becomes more obvious. 450 | 451 | # In[ ]: 452 | 453 | 454 | chart = alt.Chart(bbc_2d[bbc_2d["group"].isin(["sport", "business"])]).mark_point().encode(x="x", y="y", color="group") 455 | # Uncomment to print chart inline, but beware it will inflate the notebook size 456 | # chart 457 | 458 | 459 | # ![](./img/bbc_pca_business_sport.png) 460 | 461 | # Likewise we can see sorting by similarity produces reasonable, but not ideal, results. 462 | 463 | # In[27]: 464 | 465 | 466 | most_similar(bbc_model.paragraph_matrix.data, bbc_df, 0, n=10) 467 | 468 | 469 | # Next steps 470 | # ---------- 471 | # 472 | # That's all for now! I honestly hope that was fun and educational (it was for me, anyway). 473 | # 474 | # But data science projects are notorious for never being finished. To carry this on, we could: 475 | # 476 | # - look for better hyperparameters, since the training loss remains quite high 477 | # - benchmark against `gensim` and Ilenic's PyTorch implementation; it should be very similar to the latter 478 | # - implement the inference step for new documents, which freezes the word and output matrices and adds a new column to the paragraph matrix 479 | # - use inferred paragraph vectors as the input for a topic classifier; looking at the business/sport plot above it could be quite successful 480 | # - try visualization with a better dimensionality reduction algorithm than PCA (I've used [LargeVis](https://arxiv.org/abs/1602.00370) in the past) 481 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . -------------------------------------------------------------------------------- /doc2vec.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Doc2vec from scratch in PyTorch\n", 8 | "===============================\n", 9 | "\n", 10 | "Here we are implementing this useful algorithm with a library we know and trust. With luck this will be more accessible than reading the papers but more in-depth than typical \"install gensim and just do what I say\" tutorials, and still easy to understand for anyone whose maths skills have atrophied to nothing (like me). This is all based on the great work by [Nejc Ilenic](https://github.com/inejc/paragraph-vectors) and reading the referenced papers and gensim's source.\n", 11 | "\n", 12 | "`doc2vec` descends from `word2vec`, the basic form of which is that it is a model trained to predict the missing word in a context. Given sentences like \"the cat ___ on the mat\" it should predict \"sat\", and in doing so learn a useful representation of words. We can then extract the internal weights and re-use them as \"word embeddings\", vectors giving each word a position in N-dimensional space that is hopefully close to similar words and an appropriate distance from related words. \n", 13 | "\n", 14 | "`doc2vec` or \"Paragraph vectors\" extends the `word2vec` idea by simply adding a document id to each context. This helps the network learn associations between contexts and produces vectors that position each paragraph (document) in space." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "First we need to load the data. We'll begin by overfitting on a tiny dataset just to check all the parts fit together." 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 1, 27 | "metadata": {}, 28 | "outputs": [ 29 | { 30 | "data": { 31 | "text/html": [ 32 | "
\n", 33 | "\n", 46 | "\n", 47 | " \n", 48 | " \n", 49 | " \n", 50 | " \n", 51 | " \n", 52 | " \n", 53 | " \n", 54 | " \n", 55 | " \n", 56 | " \n", 57 | " \n", 58 | " \n", 59 | " \n", 60 | " \n", 61 | " \n", 62 | " \n", 63 | " \n", 64 | " \n", 65 | " \n", 66 | " \n", 67 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | "
texttokens
0In the week before their departure to Arrakis, when all the final scurrying about had reached a ...[in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ...
1It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide...[it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se...
2The old woman was let in by the side door down the vaulted passage by Paul's room and she was al...[the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room...
3By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could...[by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak...
\n", 77 | "
" 78 | ], 79 | "text/plain": [ 80 | " text \\\n", 81 | "0 In the week before their departure to Arrakis, when all the final scurrying about had reached a ... \n", 82 | "1 It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide... \n", 83 | "2 The old woman was let in by the side door down the vaulted passage by Paul's room and she was al... \n", 84 | "3 By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could... \n", 85 | "\n", 86 | " tokens \n", 87 | "0 [in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ... \n", 88 | "1 [it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se... \n", 89 | "2 [the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room... \n", 90 | "3 [by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak... " 91 | ] 92 | }, 93 | "execution_count": 1, 94 | "metadata": {}, 95 | "output_type": "execute_result" 96 | } 97 | ], 98 | "source": [ 99 | "import pandas as pd\n", 100 | "import spacy\n", 101 | "\n", 102 | "nlp = spacy.load(\"en_core_web_sm\")\n", 103 | "\n", 104 | "pd.set_option(\"display.max_colwidth\", 100)\n", 105 | "\n", 106 | "example_df = pd.read_csv(\"data/example.csv\")\n", 107 | "\n", 108 | "def tokenize_text(df):\n", 109 | " df[\"tokens\"] = df.text.str.lower().str.strip().apply(lambda x: [token.text.strip() for token in nlp(x) if token.text.isalnum()])\n", 110 | " return df\n", 111 | "\n", 112 | "example_df = tokenize_text(example_df)\n", 113 | "\n", 114 | "example_df" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "We will need to construct a vocabulary so we can reference every word by an ID." 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 2, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "Dataset comprises 4 documents and 106 unique words (over the limit of 1 occurrences)\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "from collections import Counter\n", 139 | "\n", 140 | "class Vocab:\n", 141 | " def __init__(self, all_tokens, min_count=2):\n", 142 | " self.min_count = min_count\n", 143 | " self.freqs = {t:n for t, n in Counter(all_tokens).items() if n >= min_count}\n", 144 | " self.words = sorted(self.freqs.keys())\n", 145 | " self.word2idx = {w: i for i, w in enumerate(self.words)}\n", 146 | " \n", 147 | "vocab = Vocab([tok for tokens in example_df.tokens for tok in tokens], min_count=1)\n", 148 | "\n", 149 | "print(f\"Dataset comprises {len(example_df)} documents and {len(vocab.words)} unique words (over the limit of {vocab.min_count} occurrences)\")" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "Words that appear extremely rarely can harm performance, so we add a simple mechanism to strip those out." 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 3, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/html": [ 167 | "
\n", 168 | "\n", 181 | "\n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | "
texttokenslengthclean_tokensclean_length
0In the week before their departure to Arrakis, when all the final scurrying about had reached a ...[in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ...32[in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ...32
1It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide...[it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se...39[it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se...39
2The old woman was let in by the side door down the vaulted passage by Paul's room and she was al...[the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room...34[the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room...34
3By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could...[by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak...53[by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak...53
\n", 227 | "
" 228 | ], 229 | "text/plain": [ 230 | " text \\\n", 231 | "0 In the week before their departure to Arrakis, when all the final scurrying about had reached a ... \n", 232 | "1 It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide... \n", 233 | "2 The old woman was let in by the side door down the vaulted passage by Paul's room and she was al... \n", 234 | "3 By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could... \n", 235 | "\n", 236 | " tokens \\\n", 237 | "0 [in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ... \n", 238 | "1 [it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se... \n", 239 | "2 [the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room... \n", 240 | "3 [by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak... \n", 241 | "\n", 242 | " length \\\n", 243 | "0 32 \n", 244 | "1 39 \n", 245 | "2 34 \n", 246 | "3 53 \n", 247 | "\n", 248 | " clean_tokens \\\n", 249 | "0 [in, the, week, before, their, departure, to, arrakis, when, all, the, final, scurrying, about, ... \n", 250 | "1 [it, was, a, warm, night, at, castle, caladan, and, the, ancient, pile, of, stone, that, had, se... \n", 251 | "2 [the, old, woman, was, let, in, by, the, side, door, down, the, vaulted, passage, by, paul, room... \n", 252 | "3 [by, the, half, light, of, a, suspensor, lamp, dimmed, and, hanging, near, the, floor, the, awak... \n", 253 | "\n", 254 | " clean_length \n", 255 | "0 32 \n", 256 | "1 39 \n", 257 | "2 34 \n", 258 | "3 53 " 259 | ] 260 | }, 261 | "execution_count": 3, 262 | "metadata": {}, 263 | "output_type": "execute_result" 264 | } 265 | ], 266 | "source": [ 267 | "def clean_tokens(df, vocab):\n", 268 | " df[\"length\"] = df.tokens.apply(len)\n", 269 | " df[\"clean_tokens\"] = df.tokens.apply(lambda x: [t for t in x if t in vocab.freqs.keys()])\n", 270 | " df[\"clean_length\"] = df.clean_tokens.apply(len)\n", 271 | " return df\n", 272 | "\n", 273 | "example_df = clean_tokens(example_df, vocab)\n", 274 | "example_df[:5]" 275 | ] 276 | }, 277 | { 278 | "cell_type": "markdown", 279 | "metadata": {}, 280 | "source": [ 281 | "The difficulty with our \"the cat _ on the mat\" problem is that the missing word could be any one in the vocabulary V and so the network would have |V| outputs for each input e.g. a huge vector containing zero for every word in the vocabulary and some positive number for \"sat\" if the network was perfectly trained. For calculating loss we need to turn that into a probabilty distribution, i.e. _softmax_ it. Computing the softmax for such a large vector is expensive.\n", 282 | "\n", 283 | "So the trick (one of many possible) we will use is _Noise Contrastive Estimation (NCE)_. We change our \"the cat _ on the mat\" problem into a multiple choice problem, asking the network to choose between \"sat\" and some random wrong answers like \"hopscotch\" and \"luxuriated\". This is easier to compute the softmax for since it's now a binary classifier (right or wrong answer) and the output is simply of a vector of size 1 + k where k is the number of random incorrect options.\n", 284 | "\n", 285 | "Happily, this alternative problem still learns equally useful word representations. We just need to adjust the examples and the loss function. There is a simplified version of the NCE loss function called _Negative Sampling (NEG)_ that we can use here.\n", 286 | "\n", 287 | "[Notes on Noise Contrastive Estimation and Negative Sampling (C. Dyer)](https://arxiv.org/abs/1410.8251) explains the derivation of the NCE and NEG loss functions.\n", 288 | "\n", 289 | "When we implement the loss function, we assume that the first element in a samples/scores vector is the score for the positive sample and the rest are negative samples. This convention saves us from having to pass around an auxiliary vector indicating which sample was positive." 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 4, 295 | "metadata": {}, 296 | "outputs": [], 297 | "source": [ 298 | "import torch.nn as nn\n", 299 | "\n", 300 | "class NegativeSampling(nn.Module):\n", 301 | " def __init__(self):\n", 302 | " super(NegativeSampling, self).__init__()\n", 303 | " self.log_sigmoid = nn.LogSigmoid()\n", 304 | " def forward(self, scores):\n", 305 | " batch_size = scores.shape[0]\n", 306 | " n_negative_samples = scores.shape[1] - 1 # TODO average or sum the negative samples? Summing seems to be correct by the paper\n", 307 | " positive = self.log_sigmoid(scores[:,0])\n", 308 | " negatives = torch.sum(self.log_sigmoid(-scores[:,1:]), dim=1)\n", 309 | " return -torch.sum(positive + negatives) / batch_size # average for batch\n", 310 | "\n", 311 | "loss = NegativeSampling()" 312 | ] 313 | }, 314 | { 315 | "cell_type": "markdown", 316 | "metadata": {}, 317 | "source": [ 318 | "It's helpful to play with some values to reassure ourselves that this function does the right thing." 319 | ] 320 | }, 321 | { 322 | "cell_type": "code", 323 | "execution_count": 5, 324 | "metadata": {}, 325 | "outputs": [ 326 | { 327 | "data": { 328 | "text/html": [ 329 | "
\n", 330 | "\n", 343 | "\n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | "
scoresloss
0[1, -1, -1, -1]tensor(1.2530)
1[0.5, -1, -1, -1]tensor(1.4139)
2[0, -1, -1, -1]tensor(1.6329)
3[0, 0, 0, 0]tensor(2.7726)
4[0, 0, 0, 1]tensor(3.3927)
5[0, 1, 1, 1]tensor(4.6329)
6[0.5, 1, 1, 1]tensor(4.4139)
7[1, 1, 1, 1]tensor(4.2530)
\n", 394 | "
" 395 | ], 396 | "text/plain": [ 397 | " scores loss\n", 398 | "0 [1, -1, -1, -1] tensor(1.2530)\n", 399 | "1 [0.5, -1, -1, -1] tensor(1.4139)\n", 400 | "2 [0, -1, -1, -1] tensor(1.6329)\n", 401 | "3 [0, 0, 0, 0] tensor(2.7726)\n", 402 | "4 [0, 0, 0, 1] tensor(3.3927)\n", 403 | "5 [0, 1, 1, 1] tensor(4.6329)\n", 404 | "6 [0.5, 1, 1, 1] tensor(4.4139)\n", 405 | "7 [1, 1, 1, 1] tensor(4.2530)" 406 | ] 407 | }, 408 | "execution_count": 5, 409 | "metadata": {}, 410 | "output_type": "execute_result" 411 | } 412 | ], 413 | "source": [ 414 | "import torch \n", 415 | "\n", 416 | "data = [[[1, -1, -1, -1]], # this dummy data uses -1 to 1, but the real model is unconstrained\n", 417 | " [[0.5, -1, -1, -1]],\n", 418 | " [[0, -1, -1, -1]],\n", 419 | " [[0, 0, 0, 0]],\n", 420 | " [[0, 0, 0, 1]],\n", 421 | " [[0, 1, 1, 1]],\n", 422 | " [[0.5, 1, 1, 1]],\n", 423 | " [[1, 1, 1, 1]]]\n", 424 | "\n", 425 | "loss_df = pd.DataFrame(data, columns=[\"scores\"])\n", 426 | "loss_df[\"loss\"] = loss_df.scores.apply(lambda x: loss(torch.FloatTensor([x])))\n", 427 | "\n", 428 | "loss_df" 429 | ] 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "metadata": {}, 434 | "source": [ 435 | "Higher scores for the positive sample (always the first element) reduce the loss but higher scores for the negative samples increase the loss. This looks like the right behaviour." 436 | ] 437 | }, 438 | { 439 | "cell_type": "markdown", 440 | "metadata": {}, 441 | "source": [ 442 | "With that in the bag, let's look at creating training data. The general idea is to create a set of examples where each example has:\n", 443 | "\n", 444 | "- doc id\n", 445 | "- sample ids - a collection of the target token and some noise tokens\n", 446 | "- context ids - tokens before and after the target token\n", 447 | "\n", 448 | "e.g. If our context size was 2, the first example from the above dataset would be:\n", 449 | "\n", 450 | "```\n", 451 | "{\"doc_id\": 0,\n", 452 | " \"sample_ids\": [word2idx[x] for x in [\"week\", \"random-word-from-vocab\", \"random-word-from-vocab\"...],\n", 453 | " \"context_ids\": [word2idx[x] for x in [\"in\", \"the\", \"before\", \"their\"]]}\n", 454 | " ```\n", 455 | " \n", 456 | " The random words are chosen according to a probability distribution:\n", 457 | " \n", 458 | " > a unigram distribution raised to the 3/4rd power, as proposed by T. Mikolov et al. in Distributed Representations of Words and Phrases and their Compositionality\n", 459 | "\n", 460 | "This has the effect of slightly increasing the relative probability of rare words (look at the graph of `y=x^0.75` below and see how the lower end is raised above `y=x`)." 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 6, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "data": { 470 | "application/vnd.vegalite.v2+json": { 471 | "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json", 472 | "config": { 473 | "view": { 474 | "height": 300, 475 | "width": 400 476 | } 477 | }, 478 | "data": { 479 | "name": "data-afc3dc0951a9e12875119a5af86e52b5" 480 | }, 481 | "datasets": { 482 | "data-afc3dc0951a9e12875119a5af86e52b5": [ 483 | { 484 | "x": 0, 485 | "y": 0 486 | }, 487 | { 488 | "x": 0.01, 489 | "y": 0.03162277660168379 490 | }, 491 | { 492 | "x": 0.02, 493 | "y": 0.053182958969449884 494 | }, 495 | { 496 | "x": 0.03, 497 | "y": 0.07208434242404263 498 | }, 499 | { 500 | "x": 0.04, 501 | "y": 0.08944271909999159 502 | }, 503 | { 504 | "x": 0.05, 505 | "y": 0.10573712634405642 506 | }, 507 | { 508 | "x": 0.06, 509 | "y": 0.12123093028059741 510 | }, 511 | { 512 | "x": 0.07, 513 | "y": 0.13608915892697748 514 | }, 515 | { 516 | "x": 0.08, 517 | "y": 0.15042412372345573 518 | }, 519 | { 520 | "x": 0.09, 521 | "y": 0.16431676725154984 522 | }, 523 | { 524 | "x": 0.1, 525 | "y": 0.1778279410038923 526 | }, 527 | { 528 | "x": 0.11, 529 | "y": 0.19100490227716513 530 | }, 531 | { 532 | "x": 0.12, 533 | "y": 0.2038853093816547 534 | }, 535 | { 536 | "x": 0.13, 537 | "y": 0.2164998073464082 538 | }, 539 | { 540 | "x": 0.14, 541 | "y": 0.22887377179317683 542 | }, 543 | { 544 | "x": 0.15, 545 | "y": 0.2410285256833955 546 | }, 547 | { 548 | "x": 0.16, 549 | "y": 0.25298221281347033 550 | }, 551 | { 552 | "x": 0.17, 553 | "y": 0.26475044029330763 554 | }, 555 | { 556 | "x": 0.18, 557 | "y": 0.2763467610958144 558 | }, 559 | { 560 | "x": 0.19, 561 | "y": 0.28778304315451386 562 | }, 563 | { 564 | "x": 0.2, 565 | "y": 0.29906975624424414 566 | }, 567 | { 568 | "x": 0.21, 569 | "y": 0.3102161981490854 570 | }, 571 | { 572 | "x": 0.22, 573 | "y": 0.32123067524150845 574 | }, 575 | { 576 | "x": 0.23, 577 | "y": 0.33212064831351956 578 | }, 579 | { 580 | "x": 0.24, 581 | "y": 0.34289285156385596 582 | }, 583 | { 584 | "x": 0.25, 585 | "y": 0.3535533905932738 586 | }, 587 | { 588 | "x": 0.26, 589 | "y": 0.3641078238014289 590 | }, 591 | { 592 | "x": 0.27, 593 | "y": 0.37456123052590357 594 | }, 595 | { 596 | "x": 0.28, 597 | "y": 0.38491826849295824 598 | }, 599 | { 600 | "x": 0.29, 601 | "y": 0.39518322257770583 602 | }, 603 | { 604 | "x": 0.3, 605 | "y": 0.4053600464421103 606 | }, 607 | { 608 | "x": 0.31, 609 | "y": 0.41545239829339137 610 | }, 611 | { 612 | "x": 0.32, 613 | "y": 0.42546367175559907 614 | }, 615 | { 616 | "x": 0.33, 617 | "y": 0.43539702265375557 618 | }, 619 | { 620 | "x": 0.34, 621 | "y": 0.4452553923589699 622 | }, 623 | { 624 | "x": 0.35000000000000003, 625 | "y": 0.45504152822405847 626 | }, 627 | { 628 | "x": 0.36, 629 | "y": 0.46475800154489 630 | }, 631 | { 632 | "x": 0.37, 633 | "y": 0.47440722340731084 634 | }, 635 | { 636 | "x": 0.38, 637 | "y": 0.4839914587188715 638 | }, 639 | { 640 | "x": 0.39, 641 | "y": 0.4935128386754873 642 | }, 643 | { 644 | "x": 0.4, 645 | "y": 0.5029733718731741 646 | }, 647 | { 648 | "x": 0.41000000000000003, 649 | "y": 0.5123749542422491 650 | }, 651 | { 652 | "x": 0.42, 653 | "y": 0.5217193779544038 654 | }, 655 | { 656 | "x": 0.43, 657 | "y": 0.5310083394307343 658 | }, 659 | { 660 | "x": 0.44, 661 | "y": 0.5402434465602292 662 | }, 663 | { 664 | "x": 0.45, 665 | "y": 0.549426225222706 666 | }, 667 | { 668 | "x": 0.46, 669 | "y": 0.5585581251971565 670 | }, 671 | { 672 | "x": 0.47000000000000003, 673 | "y": 0.5676405255254853 674 | }, 675 | { 676 | "x": 0.48, 677 | "y": 0.576674739392341 678 | }, 679 | { 680 | "x": 0.49, 681 | "y": 0.5856620185738529 682 | }, 683 | { 684 | "x": 0.5, 685 | "y": 0.5946035575013605 686 | }, 687 | { 688 | "x": 0.51, 689 | "y": 0.6035004969804791 690 | }, 691 | { 692 | "x": 0.52, 693 | "y": 0.6123539276009055 694 | }, 695 | { 696 | "x": 0.53, 697 | "y": 0.6211648928681236 698 | }, 699 | { 700 | "x": 0.54, 701 | "y": 0.629934392084505 702 | }, 703 | { 704 | "x": 0.55, 705 | "y": 0.6386633830041155 706 | }, 707 | { 708 | "x": 0.56, 709 | "y": 0.6473527842827909 710 | }, 711 | { 712 | "x": 0.5700000000000001, 713 | "y": 0.6560034777426358 714 | }, 715 | { 716 | "x": 0.58, 717 | "y": 0.6646163104680073 718 | }, 719 | { 720 | "x": 0.59, 721 | "y": 0.6731920967482075 722 | }, 723 | { 724 | "x": 0.6, 725 | "y": 0.6817316198804996 726 | }, 727 | { 728 | "x": 0.61, 729 | "y": 0.6902356338456498 730 | }, 731 | { 732 | "x": 0.62, 733 | "y": 0.6987048648669424 734 | }, 735 | { 736 | "x": 0.63, 737 | "y": 0.7071400128625219 738 | }, 739 | { 740 | "x": 0.64, 741 | "y": 0.7155417527999327 742 | }, 743 | { 744 | "x": 0.65, 745 | "y": 0.7239107359608682 746 | }, 747 | { 748 | "x": 0.66, 749 | "y": 0.7322475911233668 750 | }, 751 | { 752 | "x": 0.67, 753 | "y": 0.7405529256680135 754 | }, 755 | { 756 | "x": 0.68, 757 | "y": 0.7488273266140879 758 | }, 759 | { 760 | "x": 0.6900000000000001, 761 | "y": 0.7570713615910638 762 | }, 763 | { 764 | "x": 0.7000000000000001, 765 | "y": 0.7652855797503655 766 | }, 767 | { 768 | "x": 0.71, 769 | "y": 0.7734705126218591 770 | }, 771 | { 772 | "x": 0.72, 773 | "y": 0.7816266749191567 774 | }, 775 | { 776 | "x": 0.73, 777 | "y": 0.7897545652974598 778 | }, 779 | { 780 | "x": 0.74, 781 | "y": 0.7978546670673515 782 | }, 783 | { 784 | "x": 0.75, 785 | "y": 0.8059274488676564 786 | }, 787 | { 788 | "x": 0.76, 789 | "y": 0.8139733653002305 790 | }, 791 | { 792 | "x": 0.77, 793 | "y": 0.8219928575293057 794 | }, 795 | { 796 | "x": 0.78, 797 | "y": 0.829986353847804 798 | }, 799 | { 800 | "x": 0.79, 801 | "y": 0.837954270212839 802 | }, 803 | { 804 | "x": 0.8, 805 | "y": 0.8458970107524514 806 | }, 807 | { 808 | "x": 0.81, 809 | "y": 0.8538149682454624 810 | }, 811 | { 812 | "x": 0.8200000000000001, 813 | "y": 0.8617085245761865 814 | }, 815 | { 816 | "x": 0.8300000000000001, 817 | "y": 0.869578051165608 818 | }, 819 | { 820 | "x": 0.84, 821 | "y": 0.8774239093805121 822 | }, 823 | { 824 | "x": 0.85, 825 | "y": 0.8852464509219427 826 | }, 827 | { 828 | "x": 0.86, 829 | "y": 0.8930460181942644 830 | }, 831 | { 832 | "x": 0.87, 833 | "y": 0.9008229446560111 834 | }, 835 | { 836 | "x": 0.88, 837 | "y": 0.9085775551536168 838 | }, 839 | { 840 | "x": 0.89, 841 | "y": 0.9163101662390513 842 | }, 843 | { 844 | "x": 0.9, 845 | "y": 0.9240210864723069 846 | }, 847 | { 848 | "x": 0.91, 849 | "y": 0.9317106167096201 850 | }, 851 | { 852 | "x": 0.92, 853 | "y": 0.9393790503782488 854 | }, 855 | { 856 | "x": 0.93, 857 | "y": 0.9470266737385726 858 | }, 859 | { 860 | "x": 0.9400000000000001, 861 | "y": 0.9546537661342305 862 | }, 863 | { 864 | "x": 0.9500000000000001, 865 | "y": 0.9622606002309622 866 | }, 867 | { 868 | "x": 0.96, 869 | "y": 0.9698474422447793 870 | }, 871 | { 872 | "x": 0.97, 873 | "y": 0.9774145521600454 874 | }, 875 | { 876 | "x": 0.98, 877 | "y": 0.9849621839380145 878 | }, 879 | { 880 | "x": 0.99, 881 | "y": 0.992490585716335 882 | } 883 | ] 884 | }, 885 | "encoding": { 886 | "x": { 887 | "field": "x", 888 | "type": "quantitative" 889 | }, 890 | "y": { 891 | "field": "y", 892 | "type": "quantitative" 893 | } 894 | }, 895 | "mark": "line", 896 | "title": "x^0.75" 897 | }, 898 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcoAAAFxCAYAAADzkehqAAAgAElEQVR4Xu2dC5RlVXnnf6e6oRpXjGSUiMYHUMD4ttGAkvHRLiX46JZqtYFSg9UYzSwSQmkMFI5OV+tI3cAk3QxJBkYTaBND4wMaq2Am0SAsW4zigwZCOkYHmlHA+IBePqCBrjNrV52ib926j7PPt8+9d9/zv2uxatF3//fZ+/d95/zvPmefvRP0EQEREAEREAERaEkgERsREAEREAEREIHWBGSUyg4REAEREAERaENARqn0EAEREAEREAEZpXJABERABERABIoR0IiyGDepREAEREAEKkJARlmRQKubIiACIiACxQjIKItxk0oEfAm8H/hT4BfAbwB76yp4ObAFeAHwfeC/AZ9qcoCJrFzjV9uBs4CfNtGMAe57fURABAoSkFEWBCeZCHgQcOfZvwL/ALwDmAIuzvSrgLuA7wDrgY8A/zkzzd0djjEKXAOcDnwd+L/AVuB9Hm1TUREQgQ4EZJRKERGwE/gj4L8DbtToRoavBm4ErgTeDvw28H+A/wicDZwMPAdIgTcA12cjwv8JvAz4J2BTZpqtWvdE4F8yk30lcBzwLWBzZsT2XqkGERCBeQIySiWCCNgJuPPoi8DxwIsy4/tV4IXAA8AO4FeA1wHPA/4ZOCnTnJONAt8KXA08G7gb+Lts9NmqdR8FPgS8Cvgy8BrgBuBrwDOBg4DPAc7Ef2nvomoQgeoSkFFWN/bqeVgCzpxuA/YBv56NGr+QmZa7teqeFX4mO+RN2fNEd6v1fOAC4M3ADPA04F7gWsDdWm32eUo2knQjSDd6dZ/F27BuJOvqdc8sPwbUsmOE7a1qE4EKEZBRVijY6mrpBNxzxz/Mnhe6W6ju40Z+7wWeATya/Zt7pvi3wJGZqTld44jSTeZ5Z4sWL07q2Qhc0aLMIdnEoVuBl5Tecx1ABAaYgIxygIOrrnWVgJuxeks20ntudtvU3T7t9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rrhbmc4o3fPem7N2/qzsxuXMP3f34qXZ+eBGl+45pRv1hv60u77m4TjQRhl8DVnP6OU5vput+eWGeg/Lnld6Hs67eJ72uV/yH2mo+ddKuDXSrPF52ucupG5WnxtNuglRrq1u4+9ufPK0r74d3R5R5mmf+1HhZg27i9XdwO8Dbpu7bnzytM+1w13kneG7H2qufd0akedtn3ss4XLu1d2AVneMPO17CvC3wCuzRxMXFRdFSwAAAdlJREFUZPMMutHUPO371eyZ+MuAb2S3Yd3s11CfVtfXlUXWER/UWa+hYKseERABERCBihOQUVY8AdR9ERABERCB9gRklMoQERABERABEWhDQEap9BABERABERABGaVyQAREQAREQASKEdCIshg3qURABERABCpCQEZZkUCrmyIgAiIgAsUIyCiLcZNKBERABESgIgRklBUJtLopAiIgAiJQjICMshg3qURABERABCpCQEZZkUCrm5Un8F+B/5ItWed2aPjnbONct0ycPiIgAm0IyCiVHiJQDQJujct/yrr6k2xBdLce5qPV6L56KQLFCcgoi7OTUgRiI+AWknfbVa3Idr3v1kbDsXFSe0VgCQEZpRJCBKpDwO208nXgYOC9dbvLV4eAeioCBQjIKAtAk0QEIiSwCrgFuB34YbYZ9/OBH0TYFzVZBLpKQEbZVdw6mAj0jMDF2Z5/bg/FXwJ3ZP+5zWv1EQERaENARqn0EAEREAEREAEZpXJABERABERABIoR0IiyGDepREAEREAEKkJARlmRQKubIiACIiACxQjIKItxk0oEREAERKAiBGSUFQm0uikCIiACIlCMgIyyGDepREAEREAEKkJARlmRQKubIiACIiACxQj8f1fZJzKUyb8GAAAAAElFTkSuQmCC", 899 | "text/plain": [ 900 | "\n", 901 | "\n", 902 | "If you see this message, it means the renderer has not been properly enabled\n", 903 | "for the frontend that you are using. For more information, see\n", 904 | "https://altair-viz.github.io/user_guide/troubleshooting.html\n" 905 | ] 906 | }, 907 | "execution_count": 6, 908 | "metadata": {}, 909 | "output_type": "execute_result" 910 | } 911 | ], 912 | "source": [ 913 | "import altair as alt\n", 914 | "import numpy as np\n", 915 | "\n", 916 | "data = pd.DataFrame(zip(np.arange(0,1,0.01), np.power(np.arange(0,1,0.01), 0.75)), columns=[\"x\", \"y\"])\n", 917 | "alt.Chart(data, title=\"x^0.75\").mark_line().encode(x=\"x\", y=\"y\")" 918 | ] 919 | }, 920 | { 921 | "cell_type": "code", 922 | "execution_count": 7, 923 | "metadata": {}, 924 | "outputs": [], 925 | "source": [ 926 | "import numpy as np\n", 927 | "\n", 928 | "class NoiseDistribution:\n", 929 | " def __init__(self, vocab):\n", 930 | " self.probs = np.array([vocab.freqs[w] for w in vocab.words])\n", 931 | " self.probs = np.power(self.probs, 0.75)\n", 932 | " self.probs /= np.sum(self.probs)\n", 933 | " def sample(self, n):\n", 934 | " \"Returns the indices of n words randomly sampled from the vocabulary.\"\n", 935 | " return np.random.choice(a=self.probs.shape[0], size=n, p=self.probs)\n", 936 | " \n", 937 | "noise = NoiseDistribution(vocab)" 938 | ] 939 | }, 940 | { 941 | "cell_type": "markdown", 942 | "metadata": {}, 943 | "source": [ 944 | "With this distribution, we advance through the documents creating examples. Note that we are always putting the positive sample first in the samples vector, following the convention the loss function expects." 945 | ] 946 | }, 947 | { 948 | "cell_type": "code", 949 | "execution_count": 8, 950 | "metadata": {}, 951 | "outputs": [], 952 | "source": [ 953 | "import torch\n", 954 | "\n", 955 | "def example_generator(df, context_size, noise, n_negative_samples, vocab):\n", 956 | " for doc_id, doc in df.iterrows():\n", 957 | " for i in range(context_size, len(doc.clean_tokens) - context_size):\n", 958 | " positive_sample = vocab.word2idx[doc.clean_tokens[i]]\n", 959 | " sample_ids = noise.sample(n_negative_samples).tolist()\n", 960 | " # Fix a wee bug - ensure negative samples don't accidentally include the positive\n", 961 | " sample_ids = [sample_id if sample_id != positive_sample else -1 for sample_id in sample_ids]\n", 962 | " sample_ids.insert(0, positive_sample) \n", 963 | " context = doc.clean_tokens[i - context_size:i] + doc.clean_tokens[i + 1:i + context_size + 1]\n", 964 | " context_ids = [vocab.word2idx[w] for w in context]\n", 965 | " yield {\"doc_ids\": torch.tensor(doc_id), # we use plural here because it will be batched\n", 966 | " \"sample_ids\": torch.tensor(sample_ids), \n", 967 | " \"context_ids\": torch.tensor(context_ids)}\n", 968 | " \n", 969 | "examples = example_generator(example_df, context_size=5, noise=noise, n_negative_samples=5, vocab=vocab)" 970 | ] 971 | }, 972 | { 973 | "cell_type": "markdown", 974 | "metadata": {}, 975 | "source": [ 976 | "Now we package this up as a good old PyTorch dataset and dataloader." 977 | ] 978 | }, 979 | { 980 | "cell_type": "code", 981 | "execution_count": 9, 982 | "metadata": {}, 983 | "outputs": [], 984 | "source": [ 985 | "from torch.utils.data import Dataset, DataLoader\n", 986 | "\n", 987 | "class NCEDataset(Dataset):\n", 988 | " def __init__(self, examples):\n", 989 | " self.examples = list(examples) # just naively evaluate the whole damn thing - suboptimal!\n", 990 | " def __len__(self):\n", 991 | " return len(self.examples)\n", 992 | " def __getitem__(self, index):\n", 993 | " return self.examples[index]\n", 994 | " \n", 995 | "dataset = NCEDataset(examples)\n", 996 | "dataloader = DataLoader(dataset, batch_size=2, drop_last=True, shuffle=True) # TODO bigger batch size when not dummy data" 997 | ] 998 | }, 999 | { 1000 | "cell_type": "markdown", 1001 | "metadata": {}, 1002 | "source": [ 1003 | "It's going to also be useful to have a way to convert batches back to a readable form for debugging, so we add a helper function." 1004 | ] 1005 | }, 1006 | { 1007 | "cell_type": "code", 1008 | "execution_count": 10, 1009 | "metadata": {}, 1010 | "outputs": [ 1011 | { 1012 | "data": { 1013 | "text/plain": [ 1014 | "[{'doc_id': tensor(2),\n", 1015 | " 'context': 'was allowed a moment to ____ in at him where he',\n", 1016 | " 'context_ids': tensor([ 99, 5, 0, 61, 93, 52, 11, 48, 103, 47]),\n", 1017 | " 'samples': ['peer', 'moment', 'atreides', 'a', 'caladan', 'night'],\n", 1018 | " 'sample_ids': tensor([71, 61, 12, 0, 20, 65])},\n", 1019 | " {'doc_id': tensor(3),\n", 1020 | " 'context': 'mother the old woman was ____ witch shadow hair like matted',\n", 1021 | " 'context_ids': tensor([ 62, 91, 67, 105, 99, 104, 79, 44, 59, 60]),\n", 1022 | " 'samples': ['a', 'where', 'in', 'cooled', 'an', 'woman'],\n", 1023 | " 'sample_ids': tensor([ 0, 103, 52, 24, 6, -1])}]" 1024 | ] 1025 | }, 1026 | "execution_count": 10, 1027 | "metadata": {}, 1028 | "output_type": "execute_result" 1029 | } 1030 | ], 1031 | "source": [ 1032 | "def describe_batch(batch, vocab):\n", 1033 | " results = []\n", 1034 | " for doc_id, context_ids, sample_ids in zip(batch[\"doc_ids\"], batch[\"context_ids\"], batch[\"sample_ids\"]):\n", 1035 | " context = [vocab.words[i] for i in context_ids]\n", 1036 | " context.insert(len(context_ids) // 2, \"____\")\n", 1037 | " samples = [vocab.words[i] for i in sample_ids]\n", 1038 | " result = {\"doc_id\": doc_id,\n", 1039 | " \"context\": \" \".join(context), \n", 1040 | " \"context_ids\": context_ids, \n", 1041 | " \"samples\": samples, \n", 1042 | " \"sample_ids\": sample_ids}\n", 1043 | " results.append(result)\n", 1044 | " return results\n", 1045 | "\n", 1046 | "describe_batch(next(iter(dataloader)), vocab)" 1047 | ] 1048 | }, 1049 | { 1050 | "cell_type": "markdown", 1051 | "metadata": {}, 1052 | "source": [ 1053 | "Let's jump into creating the model itself. There isn't much to it - we multiply the input paragraph and word matrices by the output layer. Combining the paragraph and word matrices is done by summing here, but it could also be done by concatenating the inputs. The original paper actually found concatenation works better, perhaps because summing loses word order information." 1054 | ] 1055 | }, 1056 | { 1057 | "cell_type": "code", 1058 | "execution_count": 11, 1059 | "metadata": {}, 1060 | "outputs": [], 1061 | "source": [ 1062 | "import torch.nn as nn\n", 1063 | "\n", 1064 | "class DistributedMemory(nn.Module):\n", 1065 | " def __init__(self, vec_dim, n_docs, n_words):\n", 1066 | " super(DistributedMemory, self).__init__()\n", 1067 | " self.paragraph_matrix = nn.Parameter(torch.randn(n_docs, vec_dim))\n", 1068 | " self.word_matrix = nn.Parameter(torch.randn(n_words, vec_dim))\n", 1069 | " self.outputs = nn.Parameter(torch.zeros(vec_dim, n_words))\n", 1070 | " \n", 1071 | " def forward(self, doc_ids, context_ids, sample_ids):\n", 1072 | " # first add doc ids to context word ids to make the inputs\n", 1073 | " inputs = torch.add(self.paragraph_matrix[doc_ids,:], # (batch_size, vec_dim)\n", 1074 | " torch.sum(self.word_matrix[context_ids,:], dim=1)) # (batch_size, 2x context, vec_dim) -> sum to (batch_size, vec_dim)\n", 1075 | " #\n", 1076 | " # select the subset of the output layer for the NCE test\n", 1077 | " outputs = self.outputs[:,sample_ids] # (vec_dim, batch_size, n_negative_samples + 1)\n", 1078 | " #\n", 1079 | " return torch.bmm(inputs.unsqueeze(dim=1), # then multiply with some munging to make the tensor shapes line up \n", 1080 | " outputs.permute(1, 0, 2)).squeeze() # -> (batch_size, n_negative_samples + 1)\n", 1081 | "\n", 1082 | "model = DistributedMemory(vec_dim=50,\n", 1083 | " n_docs=len(example_df),\n", 1084 | " n_words=len(vocab.words))" 1085 | ] 1086 | }, 1087 | { 1088 | "cell_type": "markdown", 1089 | "metadata": {}, 1090 | "source": [ 1091 | "Let's take it for a spin!" 1092 | ] 1093 | }, 1094 | { 1095 | "cell_type": "code", 1096 | "execution_count": 12, 1097 | "metadata": {}, 1098 | "outputs": [ 1099 | { 1100 | "data": { 1101 | "text/plain": [ 1102 | "tensor([[0., 0., 0., 0., 0., 0.],\n", 1103 | " [0., 0., 0., 0., 0., 0.]])" 1104 | ] 1105 | }, 1106 | "execution_count": 12, 1107 | "metadata": {}, 1108 | "output_type": "execute_result" 1109 | } 1110 | ], 1111 | "source": [ 1112 | "with torch.no_grad():\n", 1113 | " logits = model.forward(**next(iter(dataloader)))\n", 1114 | "logits" 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "markdown", 1119 | "metadata": {}, 1120 | "source": [ 1121 | "Oh yeah, the output layer was initialized with zeros. Time to bash out a standard issue PyTorch training loop." 1122 | ] 1123 | }, 1124 | { 1125 | "cell_type": "code", 1126 | "execution_count": 13, 1127 | "metadata": {}, 1128 | "outputs": [], 1129 | "source": [ 1130 | "from tqdm import tqdm, trange\n", 1131 | "from torch.optim import Adam # ilenic uses Adam, but gensim uses plain SGD\n", 1132 | "import numpy as np\n", 1133 | "\n", 1134 | "def train(model, dataloader, epochs=40, lr=1e-3):\n", 1135 | " optimizer = Adam(model.parameters(), lr=lr)\n", 1136 | " training_losses = []\n", 1137 | " try:\n", 1138 | " for epoch in trange(epochs, desc=\"Epochs\"):\n", 1139 | " epoch_losses = []\n", 1140 | " for batch in dataloader:\n", 1141 | " model.zero_grad()\n", 1142 | " logits = model.forward(**batch)\n", 1143 | " batch_loss = loss(logits)\n", 1144 | " epoch_losses.append(batch_loss.item())\n", 1145 | " batch_loss.backward()\n", 1146 | " optimizer.step()\n", 1147 | " training_losses.append(np.mean(epoch_losses))\n", 1148 | " except KeyboardInterrupt:\n", 1149 | " print(f\"Interrupted on epoch {epoch}!\")\n", 1150 | " finally:\n", 1151 | " return training_losses" 1152 | ] 1153 | }, 1154 | { 1155 | "cell_type": "markdown", 1156 | "metadata": {}, 1157 | "source": [ 1158 | "Now we'll sanity check by overfitting the example data. Training loss should drop from untrained loss to something close to the minimum possible." 1159 | ] 1160 | }, 1161 | { 1162 | "cell_type": "code", 1163 | "execution_count": 14, 1164 | "metadata": {}, 1165 | "outputs": [ 1166 | { 1167 | "name": "stderr", 1168 | "output_type": "stream", 1169 | "text": [ 1170 | "Epochs: 100%|██████████| 40/40 [00:02<00:00, 21.83it/s]\n" 1171 | ] 1172 | } 1173 | ], 1174 | "source": [ 1175 | "training_losses = train(model, dataloader, epochs=40, lr=1e-3)" 1176 | ] 1177 | }, 1178 | { 1179 | "cell_type": "code", 1180 | "execution_count": 15, 1181 | "metadata": {}, 1182 | "outputs": [ 1183 | { 1184 | "data": { 1185 | "application/vnd.vegalite.v2+json": { 1186 | "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json", 1187 | "config": { 1188 | "view": { 1189 | "height": 300, 1190 | "width": 400 1191 | } 1192 | }, 1193 | "data": { 1194 | "name": "data-b4211a284b320247988d74ee339a35c7" 1195 | }, 1196 | "datasets": { 1197 | "data-b4211a284b320247988d74ee339a35c7": [ 1198 | { 1199 | "epoch": 0, 1200 | "training_loss": 3.873234655897496 1201 | }, 1202 | { 1203 | "epoch": 1, 1204 | "training_loss": 2.4964269541077693 1205 | }, 1206 | { 1207 | "epoch": 2, 1208 | "training_loss": 1.8195302142935283 1209 | }, 1210 | { 1211 | "epoch": 3, 1212 | "training_loss": 1.41878628124625 1213 | }, 1214 | { 1215 | "epoch": 4, 1216 | "training_loss": 1.1586913345223766 1217 | }, 1218 | { 1219 | "epoch": 5, 1220 | "training_loss": 0.9543892801818201 1221 | }, 1222 | { 1223 | "epoch": 6, 1224 | "training_loss": 0.8089911760920185 1225 | }, 1226 | { 1227 | "epoch": 7, 1228 | "training_loss": 0.690002828836441 1229 | }, 1230 | { 1231 | "epoch": 8, 1232 | "training_loss": 0.6072199561838376 1233 | }, 1234 | { 1235 | "epoch": 9, 1236 | "training_loss": 0.5273456401744131 1237 | }, 1238 | { 1239 | "epoch": 10, 1240 | "training_loss": 0.4652211883310544 1241 | }, 1242 | { 1243 | "epoch": 11, 1244 | "training_loss": 0.4105674152152013 1245 | }, 1246 | { 1247 | "epoch": 12, 1248 | "training_loss": 0.36498250900688817 1249 | }, 1250 | { 1251 | "epoch": 13, 1252 | "training_loss": 0.3294624433679096 1253 | }, 1254 | { 1255 | "epoch": 14, 1256 | "training_loss": 0.29689174738980956 1257 | }, 1258 | { 1259 | "epoch": 15, 1260 | "training_loss": 0.2668858468532562 1261 | }, 1262 | { 1263 | "epoch": 16, 1264 | "training_loss": 0.24272207208609176 1265 | }, 1266 | { 1267 | "epoch": 17, 1268 | "training_loss": 0.21813622003389618 1269 | }, 1270 | { 1271 | "epoch": 18, 1272 | "training_loss": 0.1999257556715254 1273 | }, 1274 | { 1275 | "epoch": 19, 1276 | "training_loss": 0.18043559644434412 1277 | }, 1278 | { 1279 | "epoch": 20, 1280 | "training_loss": 0.16454930458281 1281 | }, 1282 | { 1283 | "epoch": 21, 1284 | "training_loss": 0.14988945260391398 1285 | }, 1286 | { 1287 | "epoch": 22, 1288 | "training_loss": 0.1378944904496104 1289 | }, 1290 | { 1291 | "epoch": 23, 1292 | "training_loss": 0.12689736037183616 1293 | }, 1294 | { 1295 | "epoch": 24, 1296 | "training_loss": 0.11709884914048647 1297 | }, 1298 | { 1299 | "epoch": 25, 1300 | "training_loss": 0.10717140561190702 1301 | }, 1302 | { 1303 | "epoch": 26, 1304 | "training_loss": 0.09873407258320663 1305 | }, 1306 | { 1307 | "epoch": 27, 1308 | "training_loss": 0.09167827893111666 1309 | }, 1310 | { 1311 | "epoch": 28, 1312 | "training_loss": 0.08547388257111534 1313 | }, 1314 | { 1315 | "epoch": 29, 1316 | "training_loss": 0.0792784820610689 1317 | }, 1318 | { 1319 | "epoch": 30, 1320 | "training_loss": 0.07406510791536104 1321 | }, 1322 | { 1323 | "epoch": 31, 1324 | "training_loss": 0.06805220107405872 1325 | }, 1326 | { 1327 | "epoch": 32, 1328 | "training_loss": 0.064012377917514 1329 | }, 1330 | { 1331 | "epoch": 33, 1332 | "training_loss": 0.06023278630385965 1333 | }, 1334 | { 1335 | "epoch": 34, 1336 | "training_loss": 0.05617725763911918 1337 | }, 1338 | { 1339 | "epoch": 35, 1340 | "training_loss": 0.05255285915681871 1341 | }, 1342 | { 1343 | "epoch": 36, 1344 | "training_loss": 0.04945897159434981 1345 | }, 1346 | { 1347 | "epoch": 37, 1348 | "training_loss": 0.047309281130842235 1349 | }, 1350 | { 1351 | "epoch": 38, 1352 | "training_loss": 0.04321649504857043 1353 | }, 1354 | { 1355 | "epoch": 39, 1356 | "training_loss": 0.040696044799761244 1357 | } 1358 | ] 1359 | }, 1360 | "encoding": { 1361 | "x": { 1362 | "field": "epoch", 1363 | "type": "quantitative" 1364 | }, 1365 | "y": { 1366 | "field": "training_loss", 1367 | "scale": { 1368 | "type": "log" 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t1eRa9OtyAwfAQgyuFjTo8gUASB344I8Q2SfijpXklTkv6HJCO22yT9fpQndLWkX48uV/5mlAD6b6P8pq+LLgewS4G/IenfRDcqfCdKeG53tlp7t0T5kf+zpFMl2U32PCAwUghAlCM13LxsAxAwj9E8w/jzOUl2tZwR21skGcldJMnu4DNCNMLcJMmSgP9M0oSkWyMv1AjXLjZfKumpWKPt0KvdAv95SXa7iZWzGy32NQBHXgEEUiMAUaaGioIgUAsE2jdh9CO2NlFeHHmOZ0iyDTl2+4SFVu0mijaJ2tVIRqIbo6uQ7ILg9tO9Rml3T5rnalcTdd8xWAtgEAIEQiEAUYZClnZBIAwC/0rSV6Lb2s1ztPsKzcu8P/IozVN8Z3TvqnmLFnq1K5BsPdJud/9k5E1ayPVESa+VdLekd0m6Q9K3JNm6p10/ZR5qe9crRBlmPGnVAQIQpYNBQkQQ6ELgmogo/1kUFjViNM/RiO1votDqs9EGHVtjtMfu4TSyO07SP0h6j6T7or/Z5iDb3GOhWbur9UpJJ0OU6B0IzCMAUaIJINAMBNqhUgul3tmMV+ItQKAeCECU9RgHpACBoghw7rEogtQHgT4IQJSoBgg0AwGIshnjyFvUEAGIsoaDgkggAAIgAAL1QQCirM9YIAkIgAAIgEANEYAoazgoiAQCIAACIFAfBCDK+owFkoAACIAACNQQAYiyhoOCSCAAAiAAAvVB4P8D+77+ovte0PAAAAAASUVORK5CYII=", 1376 | "text/plain": [ 1377 | "\n", 1378 | "\n", 1379 | "If you see this message, it means the renderer has not been properly enabled\n", 1380 | "for the frontend that you are using. For more information, see\n", 1381 | "https://altair-viz.github.io/user_guide/troubleshooting.html\n" 1382 | ] 1383 | }, 1384 | "execution_count": 15, 1385 | "metadata": {}, 1386 | "output_type": "execute_result" 1387 | } 1388 | ], 1389 | "source": [ 1390 | "import altair as alt\n", 1391 | "\n", 1392 | "df_loss = pd.DataFrame(enumerate(training_losses), columns=[\"epoch\", \"training_loss\"])\n", 1393 | "alt.Chart(df_loss).mark_bar().encode(alt.X(\"epoch\"), alt.Y(\"training_loss\", scale=alt.Scale(type=\"log\")))" 1394 | ] 1395 | }, 1396 | { 1397 | "cell_type": "markdown", 1398 | "metadata": {}, 1399 | "source": [ 1400 | "And because we're paranoid types, let's check a prediction." 1401 | ] 1402 | }, 1403 | { 1404 | "cell_type": "code", 1405 | "execution_count": 16, 1406 | "metadata": {}, 1407 | "outputs": [ 1408 | { 1409 | "data": { 1410 | "text/plain": [ 1411 | "tensor([[ 4.0063, -7.1900, -6.8099, -5.7869, -6.4321, -3.4320],\n", 1412 | " [ 4.9544, -6.3152, -7.6040, -6.6827, -7.8661, -5.0460]])" 1413 | ] 1414 | }, 1415 | "execution_count": 16, 1416 | "metadata": {}, 1417 | "output_type": "execute_result" 1418 | } 1419 | ], 1420 | "source": [ 1421 | "with torch.no_grad():\n", 1422 | " logits = model.forward(**next(iter(dataloader)))\n", 1423 | "logits" 1424 | ] 1425 | }, 1426 | { 1427 | "cell_type": "markdown", 1428 | "metadata": {}, 1429 | "source": [ 1430 | "The positive sample gets a positive score and the negatives get negative scores. Super." 1431 | ] 1432 | }, 1433 | { 1434 | "cell_type": "markdown", 1435 | "metadata": {}, 1436 | "source": [ 1437 | "We should be able get the paragraph vectors for the documents and do things like check these for similarity to one another." 1438 | ] 1439 | }, 1440 | { 1441 | "cell_type": "code", 1442 | "execution_count": 17, 1443 | "metadata": {}, 1444 | "outputs": [ 1445 | { 1446 | "data": { 1447 | "text/html": [ 1448 | "
\n", 1449 | "\n", 1462 | "\n", 1463 | " \n", 1464 | " \n", 1465 | " \n", 1466 | " \n", 1467 | " \n", 1468 | " \n", 1469 | " \n", 1470 | " \n", 1471 | " \n", 1472 | " \n", 1473 | " \n", 1474 | " \n", 1475 | " \n", 1476 | " \n", 1477 | " \n", 1478 | " \n", 1479 | " \n", 1480 | " \n", 1481 | " \n", 1482 | " \n", 1483 | " \n", 1484 | " \n", 1485 | " \n", 1486 | " \n", 1487 | " \n", 1488 | " \n", 1489 | " \n", 1490 | " \n", 1491 | " \n", 1492 | " \n", 1493 | " \n", 1494 | " \n", 1495 | " \n", 1496 | " \n", 1497 | "
doc_idsimilaritytext
111.000000It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide...
000.177416In the week before their departure to Arrakis, when all the final scurrying about had reached a ...
330.081760By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could...
22-0.044768The old woman was let in by the side door down the vaulted passage by Paul's room and she was al...
\n", 1498 | "
" 1499 | ], 1500 | "text/plain": [ 1501 | " doc_id similarity \\\n", 1502 | "1 1 1.000000 \n", 1503 | "0 0 0.177416 \n", 1504 | "3 3 0.081760 \n", 1505 | "2 2 -0.044768 \n", 1506 | "\n", 1507 | " text \n", 1508 | "1 It was a warm night at Castle Caladan, and the ancient pile of stone that had served the Atreide... \n", 1509 | "0 In the week before their departure to Arrakis, when all the final scurrying about had reached a ... \n", 1510 | "3 By the half-light of a suspensor lamp, dimmed and hanging near the floor, the awakened boy could... \n", 1511 | "2 The old woman was let in by the side door down the vaulted passage by Paul's room and she was al... " 1512 | ] 1513 | }, 1514 | "execution_count": 17, 1515 | "metadata": {}, 1516 | "output_type": "execute_result" 1517 | } 1518 | ], 1519 | "source": [ 1520 | "from sklearn.preprocessing import normalize\n", 1521 | "\n", 1522 | "def most_similar(paragraph_matrix, docs_df, index, n=None):\n", 1523 | " pm = normalize(paragraph_matrix, norm=\"l2\") # in a smarter implementation we would cache this somewhere\n", 1524 | " sims = np.dot(pm, pm[index,:])\n", 1525 | " df = pd.DataFrame(enumerate(sims), columns=[\"doc_id\", \"similarity\"])\n", 1526 | " n = n if n is not None else len(sims)\n", 1527 | " return df.merge(docs_df[[\"text\"]].reset_index(drop=True), left_index=True, right_index=True).sort_values(by=\"similarity\", ascending=False)[:n]\n", 1528 | "\n", 1529 | "most_similar(model.paragraph_matrix.data, example_df, 1, n=10)" 1530 | ] 1531 | }, 1532 | { 1533 | "cell_type": "markdown", 1534 | "metadata": {}, 1535 | "source": [ 1536 | "It's not particularly illuminating for our tiny set of dummy data though. We can also use PCA to reduce our n-dimensional paragraph vectors to 2 dimensions and see if they are clustered nicely." 1537 | ] 1538 | }, 1539 | { 1540 | "cell_type": "code", 1541 | "execution_count": 18, 1542 | "metadata": {}, 1543 | "outputs": [ 1544 | { 1545 | "name": "stdout", 1546 | "output_type": "stream", 1547 | "text": [ 1548 | "2-component PCA, explains 48.18% of variance\n" 1549 | ] 1550 | }, 1551 | { 1552 | "data": { 1553 | "application/vnd.vegalite.v2+json": { 1554 | "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json", 1555 | "config": { 1556 | "view": { 1557 | "height": 300, 1558 | "width": 400 1559 | } 1560 | }, 1561 | "data": { 1562 | "name": "data-0b1e0474027b1da095c3ed8d1f5f386e" 1563 | }, 1564 | "datasets": { 1565 | "data-0b1e0474027b1da095c3ed8d1f5f386e": [ 1566 | { 1567 | "group": "0", 1568 | "x": -4.767539597377173, 1569 | "y": -4.756888669464686 1570 | }, 1571 | { 1572 | "group": "1", 1573 | "x": -3.202457816084362, 1574 | "y": 6.363203538611249 1575 | }, 1576 | { 1577 | "group": "2", 1578 | "x": 6.650774519184007, 1579 | "y": -0.034075790016020964 1580 | }, 1581 | { 1582 | "group": "3", 1583 | "x": 1.3192228942775253, 1584 | "y": -1.572239079130542 1585 | } 1586 | ] 1587 | }, 1588 | "encoding": { 1589 | "color": { 1590 | "field": "group", 1591 | "type": "nominal" 1592 | }, 1593 | "x": { 1594 | "field": "x", 1595 | "type": "quantitative" 1596 | }, 1597 | "y": { 1598 | "field": "y", 1599 | "type": "quantitative" 1600 | } 1601 | }, 1602 | "mark": "point" 1603 | }, 1604 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfwAAAFZCAYAAAB9g51OAAAgAElEQVR4Xu2dC5RdVZnn//tWeBiwfXRjsHmksRCVbnSle2xsF4M4tEIgCYgWCciAoEtcOgpCgEqQR6NQxSug2LToNAIuQyoKYsLDHh/YIz7QaekR2wEGpEEeAW3FHl4tqXt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+p/4IEfARffqf4Xkv5V0ockxSPVXv30eoc//bliIcVThri7j29YO68Pr1/HVXu87/Sfl0l6qlcG1D6l8J26++1Uez2/F2FMvUs/nnA8JulYST/qxY2n3SN+UqOfGkyF4pAPDnVRb3+/+kS/++OUDvFYPy6K46Yg9uhevsk5vrwU30j7lh7XZF9uN+g7/L6Iyk1RAAVQAAVQwE0BgO/mCPGgAAqgAAqgQAkKAPwSROWSKIACKIACKOCmAMB3c4R4UAAFUAAFUKAEBQB+CaJySRRAARRAARRwUwDguzlCPCiAAiiAAihQggIAvwRRuSQKoAAKoAAKuCkA8N0cIR4UQAEUQAEUKEEBgF+CqFwSBVAABVAABdwUAPhujhAPCqAACqAACpSgAMAvQVQuiQJmCpwt6czan5iOf9b4XyR9TlL8k6b8oAAKzBAFAP4MMZrHnNEKzJL0g5oC/1b7Qqn49/VfmNGq8PAoMMMUAPgzzHAed8YqEL80Jn716JCkvSQ9OGOV4MFRYIYqAPBnqPE89oxTIH5r4g8lbSvp/ZL++4xTgAdGgRmuAMCf4QnA488IBbavfSXv3ZKekBS/qvdPJT06I56eh0QBFNigAMAnEVBg8BX4pKR3S4rf/f2spJ/W/lk4+I/OE6IACkwpAPDJBRRAARRAARSYAQoA/BlgMo+IAiiAAiiAAgCfHEABFEABFECBGaAAwJ8BJvOIKIACKIACKADwyQEUQAEUQAEUmAEKAPwZYDKPiAIogAIogAIAnxxAARRAARRAgRmgAMCfASbziCiAAiiAAijw/wH+7Ig4wU4A1QAAAABJRU5ErkJggg==", 1605 | "text/plain": [ 1606 | "\n", 1607 | "\n", 1608 | "If you see this message, it means the renderer has not been properly enabled\n", 1609 | "for the frontend that you are using. For more information, see\n", 1610 | "https://altair-viz.github.io/user_guide/troubleshooting.html\n" 1611 | ] 1612 | }, 1613 | "execution_count": 18, 1614 | "metadata": {}, 1615 | "output_type": "execute_result" 1616 | } 1617 | ], 1618 | "source": [ 1619 | "from sklearn.decomposition import PCA\n", 1620 | "\n", 1621 | "def pca_2d(paragraph_matrix, groups):\n", 1622 | " pca = PCA(n_components=2)\n", 1623 | " reduced_dims = pca.fit_transform(paragraph_matrix)\n", 1624 | " print(f\"2-component PCA, explains {sum(pca.explained_variance_):.2f}% of variance\")\n", 1625 | " df = pd.DataFrame(reduced_dims, columns=[\"x\", \"y\"])\n", 1626 | " df[\"group\"] = groups\n", 1627 | " return df\n", 1628 | "\n", 1629 | "example_2d = pca_2d(model.paragraph_matrix.data, [\"0\",\"1\",\"2\",\"3\"])\n", 1630 | "alt.Chart(example_2d).mark_point().encode(x=\"x\", y=\"y\", color=\"group\")" 1631 | ] 1632 | }, 1633 | { 1634 | "cell_type": "markdown", 1635 | "metadata": {}, 1636 | "source": [ 1637 | "Not much to see on such a tiny dataset without any labelled groups." 1638 | ] 1639 | }, 1640 | { 1641 | "cell_type": "markdown", 1642 | "metadata": {}, 1643 | "source": [ 1644 | "Running this on some bigger data\n", 1645 | "--------------------------------\n", 1646 | "\n", 1647 | "We'll use the BBC's dataset. The dataset was created by Derek Greene at UCD and all articles are copyright Auntie. I've munged it into a file per topic." 1648 | ] 1649 | }, 1650 | { 1651 | "cell_type": "code", 1652 | "execution_count": 19, 1653 | "metadata": {}, 1654 | "outputs": [ 1655 | { 1656 | "data": { 1657 | "text/html": [ 1658 | "
\n", 1659 | "\n", 1672 | "\n", 1673 | " \n", 1674 | " \n", 1675 | " \n", 1676 | " \n", 1677 | " \n", 1678 | " \n", 1679 | " \n", 1680 | " \n", 1681 | " \n", 1682 | " \n", 1683 | " \n", 1684 | " \n", 1685 | " \n", 1686 | " \n", 1687 | " \n", 1688 | " \n", 1689 | " \n", 1690 | " \n", 1691 | " \n", 1692 | " \n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | "
texttokensgroup
0Claxton hunting first major medal British hurdler Sarah Claxton is confident she can win her fi...[claxton, hunting, first, major, medal, british, hurdler, sarah, claxton, is, confident, she, ca...sport
1O'Sullivan could run in Worlds Sonia O'Sullivan has indicated that she would like to participat...[could, run, in, worlds, sonia, has, indicated, that, she, would, like, to, participate, in, nex...sport
2Greene sets sights on world title Maurice Greene aims to wipe out the pain of losing his Olympi...[greene, sets, sights, on, world, title, maurice, greene, aims, to, wipe, out, the, pain, of, lo...sport
3IAAF launches fight against drugs The IAAF - athletics' world governing body - has met anti-dop...[iaaf, launches, fight, against, drugs, the, iaaf, athletics, world, governing, body, has, met, ...sport
\n", 1708 | "
" 1709 | ], 1710 | "text/plain": [ 1711 | " text \\\n", 1712 | "0 Claxton hunting first major medal British hurdler Sarah Claxton is confident she can win her fi... \n", 1713 | "1 O'Sullivan could run in Worlds Sonia O'Sullivan has indicated that she would like to participat... \n", 1714 | "2 Greene sets sights on world title Maurice Greene aims to wipe out the pain of losing his Olympi... \n", 1715 | "3 IAAF launches fight against drugs The IAAF - athletics' world governing body - has met anti-dop... \n", 1716 | "\n", 1717 | " tokens \\\n", 1718 | "0 [claxton, hunting, first, major, medal, british, hurdler, sarah, claxton, is, confident, she, ca... \n", 1719 | "1 [could, run, in, worlds, sonia, has, indicated, that, she, would, like, to, participate, in, nex... \n", 1720 | "2 [greene, sets, sights, on, world, title, maurice, greene, aims, to, wipe, out, the, pain, of, lo... \n", 1721 | "3 [iaaf, launches, fight, against, drugs, the, iaaf, athletics, world, governing, body, has, met, ... \n", 1722 | "\n", 1723 | " group \n", 1724 | "0 sport \n", 1725 | "1 sport \n", 1726 | "2 sport \n", 1727 | "3 sport " 1728 | ] 1729 | }, 1730 | "execution_count": 19, 1731 | "metadata": {}, 1732 | "output_type": "execute_result" 1733 | } 1734 | ], 1735 | "source": [ 1736 | "dfs = []\n", 1737 | "for document_set in (\"sport\",\n", 1738 | " \"business\",\n", 1739 | " \"politics\", \n", 1740 | " \"tech\", \n", 1741 | " \"entertainment\"):\n", 1742 | " df_ = pd.read_csv(f\"data/bbc/{document_set}.csv.bz2\", encoding=\"latin1\")\n", 1743 | " df_ = tokenize_text(df_)\n", 1744 | " df_[\"group\"] = document_set\n", 1745 | " dfs.append(df_)\n", 1746 | "\n", 1747 | "bbc_df = pd.concat(dfs)\n", 1748 | "bbc_df[:4]" 1749 | ] 1750 | }, 1751 | { 1752 | "cell_type": "code", 1753 | "execution_count": 20, 1754 | "metadata": {}, 1755 | "outputs": [ 1756 | { 1757 | "name": "stdout", 1758 | "output_type": "stream", 1759 | "text": [ 1760 | "Dataset comprises 2225 documents and 19063 unique words\n" 1761 | ] 1762 | } 1763 | ], 1764 | "source": [ 1765 | "bbc_vocab = Vocab([tok for tokens in bbc_df.tokens for tok in tokens])\n", 1766 | "\n", 1767 | "bbc_df = clean_tokens(bbc_df, bbc_vocab)\n", 1768 | "\n", 1769 | "print(f\"Dataset comprises {len(bbc_df)} documents and {len(bbc_vocab.words)} unique words\")" 1770 | ] 1771 | }, 1772 | { 1773 | "cell_type": "code", 1774 | "execution_count": 21, 1775 | "metadata": {}, 1776 | "outputs": [], 1777 | "source": [ 1778 | "bbc_noise = NoiseDistribution(bbc_vocab)\n", 1779 | "bbc_examples = list(example_generator(bbc_df, context_size=5, noise=bbc_noise, n_negative_samples=5, vocab=bbc_vocab))" 1780 | ] 1781 | }, 1782 | { 1783 | "cell_type": "code", 1784 | "execution_count": 22, 1785 | "metadata": {}, 1786 | "outputs": [], 1787 | "source": [ 1788 | "bbc_dataset = NCEDataset(bbc_examples)\n", 1789 | "bbc_dataloader = DataLoader(bbc_dataset, batch_size=1024, drop_last=True, shuffle=True) # TODO could tolerate a larger batch size\n", 1790 | "\n", 1791 | "bbc_model = DistributedMemory(vec_dim=50,\n", 1792 | " n_docs=len(bbc_df),\n", 1793 | " n_words=len(bbc_vocab.words))" 1794 | ] 1795 | }, 1796 | { 1797 | "cell_type": "code", 1798 | "execution_count": 23, 1799 | "metadata": {}, 1800 | "outputs": [ 1801 | { 1802 | "name": "stderr", 1803 | "output_type": "stream", 1804 | "text": [ 1805 | "Epochs: 100%|██████████| 80/80 [36:14<00:00, 26.78s/it]\n" 1806 | ] 1807 | } 1808 | ], 1809 | "source": [ 1810 | "bbc_training_losses = train(bbc_model, bbc_dataloader, epochs=80, lr=1e-3)" 1811 | ] 1812 | }, 1813 | { 1814 | "cell_type": "code", 1815 | "execution_count": 24, 1816 | "metadata": {}, 1817 | "outputs": [ 1818 | { 1819 | "data": { 1820 | "application/vnd.vegalite.v2+json": { 1821 | "$schema": "https://vega.github.io/schema/vega-lite/v2.6.0.json", 1822 | "config": { 1823 | "view": { 1824 | "height": 300, 1825 | "width": 400 1826 | } 1827 | }, 1828 | "data": { 1829 | "name": "data-1dabe6fce07510d2b0d23042635cb568" 1830 | }, 1831 | "datasets": { 1832 | "data-1dabe6fce07510d2b0d23042635cb568": [ 1833 | { 1834 | "epoch": 0, 1835 | "training_loss": 2.642270294331616 1836 | }, 1837 | { 1838 | "epoch": 1, 1839 | "training_loss": 2.1742215334258463 1840 | }, 1841 | { 1842 | "epoch": 2, 1843 | "training_loss": 1.990165346749821 1844 | }, 1845 | { 1846 | "epoch": 3, 1847 | "training_loss": 1.873253081452032 1848 | }, 1849 | { 1850 | "epoch": 4, 1851 | "training_loss": 1.789763425596012 1852 | }, 1853 | { 1854 | "epoch": 5, 1855 | "training_loss": 1.7244694537997987 1856 | }, 1857 | { 1858 | "epoch": 6, 1859 | "training_loss": 1.670895414915144 1860 | }, 1861 | { 1862 | "epoch": 7, 1863 | "training_loss": 1.6244636086943727 1864 | }, 1865 | { 1866 | "epoch": 8, 1867 | "training_loss": 1.5836919797873645 1868 | }, 1869 | { 1870 | "epoch": 9, 1871 | "training_loss": 1.5470218249729701 1872 | }, 1873 | { 1874 | "epoch": 10, 1875 | "training_loss": 1.5139503951398483 1876 | }, 1877 | { 1878 | "epoch": 11, 1879 | "training_loss": 1.4832230216968134 1880 | }, 1881 | { 1882 | "epoch": 12, 1883 | "training_loss": 1.4547421681954993 1884 | }, 1885 | { 1886 | "epoch": 13, 1887 | "training_loss": 1.4282586559745836 1888 | }, 1889 | { 1890 | "epoch": 14, 1891 | "training_loss": 1.403701515079285 1892 | }, 1893 | { 1894 | "epoch": 15, 1895 | "training_loss": 1.3798937556166087 1896 | }, 1897 | { 1898 | "epoch": 16, 1899 | "training_loss": 1.3577345677784511 1900 | }, 1901 | { 1902 | "epoch": 17, 1903 | "training_loss": 1.3366852766238384 1904 | }, 1905 | { 1906 | "epoch": 18, 1907 | "training_loss": 1.3162777810363295 1908 | }, 1909 | { 1910 | "epoch": 19, 1911 | "training_loss": 1.2970764010589315 1912 | }, 1913 | { 1914 | "epoch": 20, 1915 | "training_loss": 1.2788146187800058 1916 | }, 1917 | { 1918 | "epoch": 21, 1919 | "training_loss": 1.2611135737496133 1920 | }, 1921 | { 1922 | "epoch": 22, 1923 | "training_loss": 1.2440896054972772 1924 | }, 1925 | { 1926 | "epoch": 23, 1927 | "training_loss": 1.2277287255162779 1928 | }, 1929 | { 1930 | "epoch": 24, 1931 | "training_loss": 1.211776340229911 1932 | }, 1933 | { 1934 | "epoch": 25, 1935 | "training_loss": 1.1965603542624053 1936 | }, 1937 | { 1938 | "epoch": 26, 1939 | "training_loss": 1.1817405841365365 1940 | }, 1941 | { 1942 | "epoch": 27, 1943 | "training_loss": 1.1673207131972223 1944 | }, 1945 | { 1946 | "epoch": 28, 1947 | "training_loss": 1.1533892758884785 1948 | }, 1949 | { 1950 | "epoch": 29, 1951 | "training_loss": 1.1397850001080436 1952 | }, 1953 | { 1954 | "epoch": 30, 1955 | "training_loss": 1.12681249217217 1956 | }, 1957 | { 1958 | "epoch": 31, 1959 | "training_loss": 1.1138663835407043 1960 | }, 1961 | { 1962 | "epoch": 32, 1963 | "training_loss": 1.1015954906896035 1964 | }, 1965 | { 1966 | "epoch": 33, 1967 | "training_loss": 1.089359670544263 1968 | }, 1969 | { 1970 | "epoch": 34, 1971 | "training_loss": 1.0776376641314962 1972 | }, 1973 | { 1974 | "epoch": 35, 1975 | "training_loss": 1.0659556754627584 1976 | }, 1977 | { 1978 | "epoch": 36, 1979 | "training_loss": 1.0547422724480955 1980 | }, 1981 | { 1982 | "epoch": 37, 1983 | "training_loss": 1.0438089944561075 1984 | }, 1985 | { 1986 | "epoch": 38, 1987 | "training_loss": 1.0329133888209088 1988 | }, 1989 | { 1990 | "epoch": 39, 1991 | "training_loss": 1.0227227165832282 1992 | }, 1993 | { 1994 | "epoch": 40, 1995 | "training_loss": 1.0123565251042383 1996 | }, 1997 | { 1998 | "epoch": 41, 1999 | "training_loss": 1.0023637906364773 2000 | }, 2001 | { 2002 | "epoch": 42, 2003 | "training_loss": 0.9926695086200785 2004 | }, 2005 | { 2006 | "epoch": 43, 2007 | "training_loss": 0.982954163951163 2008 | }, 2009 | { 2010 | "epoch": 44, 2011 | "training_loss": 0.9737152805239517 2012 | }, 2013 | { 2014 | "epoch": 45, 2015 | "training_loss": 0.9645086004867317 2016 | }, 2017 | { 2018 | "epoch": 46, 2019 | "training_loss": 0.9555849193786242 2020 | }, 2021 | { 2022 | "epoch": 47, 2023 | "training_loss": 0.9466561066437952 2024 | }, 2025 | { 2026 | "epoch": 48, 2027 | "training_loss": 0.9380779170101474 2028 | }, 2029 | { 2030 | "epoch": 49, 2031 | "training_loss": 0.929785754813911 2032 | }, 2033 | { 2034 | "epoch": 50, 2035 | "training_loss": 0.9214358320147354 2036 | }, 2037 | { 2038 | "epoch": 51, 2039 | "training_loss": 0.9133923515770006 2040 | }, 2041 | { 2042 | "epoch": 52, 2043 | "training_loss": 0.905320764328382 2044 | }, 2045 | { 2046 | "epoch": 53, 2047 | "training_loss": 0.8976051105475574 2048 | }, 2049 | { 2050 | "epoch": 54, 2051 | "training_loss": 0.8899229808623746 2052 | }, 2053 | { 2054 | "epoch": 55, 2055 | "training_loss": 0.8823469078318673 2056 | }, 2057 | { 2058 | "epoch": 56, 2059 | "training_loss": 0.8750101461173585 2060 | }, 2061 | { 2062 | "epoch": 57, 2063 | "training_loss": 0.867823110456052 2064 | }, 2065 | { 2066 | "epoch": 58, 2067 | "training_loss": 0.8607556018029681 2068 | }, 2069 | { 2070 | "epoch": 59, 2071 | "training_loss": 0.8537966694891083 2072 | }, 2073 | { 2074 | "epoch": 60, 2075 | "training_loss": 0.8470302788367182 2076 | }, 2077 | { 2078 | "epoch": 61, 2079 | "training_loss": 0.8402785332306572 2080 | }, 2081 | { 2082 | "epoch": 62, 2083 | "training_loss": 0.8336316384884142 2084 | }, 2085 | { 2086 | "epoch": 63, 2087 | "training_loss": 0.8271638499283642 2088 | }, 2089 | { 2090 | "epoch": 64, 2091 | "training_loss": 0.8209897966118332 2092 | }, 2093 | { 2094 | "epoch": 65, 2095 | "training_loss": 0.8146745335981712 2096 | }, 2097 | { 2098 | "epoch": 66, 2099 | "training_loss": 0.8085972012940401 2100 | }, 2101 | { 2102 | "epoch": 67, 2103 | "training_loss": 0.8024606412982348 2104 | }, 2105 | { 2106 | "epoch": 68, 2107 | "training_loss": 0.7965273064856203 2108 | }, 2109 | { 2110 | "epoch": 69, 2111 | "training_loss": 0.7905283134916554 2112 | }, 2113 | { 2114 | "epoch": 70, 2115 | "training_loss": 0.785075603212629 2116 | }, 2117 | { 2118 | "epoch": 71, 2119 | "training_loss": 0.7794511792822654 2120 | }, 2121 | { 2122 | "epoch": 72, 2123 | "training_loss": 0.7739284674573389 2124 | }, 2125 | { 2126 | "epoch": 73, 2127 | "training_loss": 0.7684736896745907 2128 | }, 2129 | { 2130 | "epoch": 74, 2131 | "training_loss": 0.7630798336141598 2132 | }, 2133 | { 2134 | "epoch": 75, 2135 | "training_loss": 0.7578280769519924 2136 | }, 2137 | { 2138 | "epoch": 76, 2139 | "training_loss": 0.7526835779966035 2140 | }, 2141 | { 2142 | "epoch": 77, 2143 | "training_loss": 0.7476536778189381 2144 | }, 2145 | { 2146 | "epoch": 78, 2147 | "training_loss": 0.7426093139263413 2148 | }, 2149 | { 2150 | "epoch": 79, 2151 | "training_loss": 0.7375516610856382 2152 | } 2153 | ] 2154 | }, 2155 | "encoding": { 2156 | "x": { 2157 | "field": "epoch", 2158 | "type": "quantitative" 2159 | }, 2160 | "y": { 2161 | "field": "training_loss", 2162 | "type": "quantitative" 2163 | } 2164 | }, 2165 | "mark": "bar" 2166 | }, 2167 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAcoAAAFZCAYAAAAYbm8xAAAgAElEQVR4Xu2dC7QlVZnff6dRQaODxmFGRWOw8UWiBhAHZxlHx7dRGJNppPER8ZFJ1Dhmoq52loZuUe8FE3FFx1FxfOEIikSlm4dRGJ+oKKBg0HFkBlTAxOf4QkVuZW2oC+eevufeXfVVnburz++s1avh9v7vs+v3fbX/99tVtWuEHwlIQAISkIAEphIYyUYCEpCABCQggekENEqzQwISkIAEJLAGAY3S9JCABCQgAQlolOaABCQgAQlIoB2BPa6i3LlzZ3XQQQe1o6FKAhKQgATmmsDmzZt388U9zigXFxerbdu2FXtcV1xxRbVaIErJTMcXi4T85BcjEFObf/3wK9ZQ2h6uRtmW3E06TzT5xQjE1Oaf/GIEYupp+adRxrg2VjsRNEa2QiA/+cUIxNTm33zy0yhjcW+s9kRrjEyjjCGTn/w6JBDraqjzn0YZi3tj9VATpfGB9iSQXwys/OQXIxBTDzX/NMpY3Burh5oojQ+0J4H8YmDlJ78YgZh6qPmnUcbi3lg91ERpfKA9CeQXAys/+cUIxNRDzT+NMhb3xuqhJkrjA+1JIL8YWPnJL0Ygph5q/mmUsbg3Vg81URofaE8C+cXAyk9+MQIx9VDzT6OMxb2xeqiJ0vhAexLILwZWfvKLEYiph5p/GmUs7o3VQ02Uxgfak0B+MbDyk1+MQEw91PzTKGNxb6weaqI0PtCeBPKLgZWf/GIEYuqh5p9GGYt7Y/VQE6XxgfYkkF8MrPzkFyMQUw81/zTKWNwbq4eaKI0PtCeB/GJg5Se/GIGYeqj5p1HG4t5YPdREaXygPQnkFwMrP/nFCMTUQ80/jTIW9yz1ES879W7LDbc/4+Crt59yyf7p/888ces1WR3MsNFQ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NI1xvRJ705MZrc/8GXgT4GL6n9LNwelm3vS0mx6H+RzgftqlBsdZr+/FAIaZSmRcBwSiBFYXipNS6kfjXWlWgISGCegUZoPEtgzCPjc454RR4+iQAIaZYFBcUgSaEFAo2wBTYkEcgholDmUbCMBCUhAAnNLQKOc29B74BKQgAQkkENAo8yhZBsJSEACEphbAhrl3IbeA5eABCQggRwCGmUOJdtIQAISkMDcEvj/bAzS/QHkyUQAAAAASUVORK5CYII=", 2168 | "text/plain": [ 2169 | "\n", 2170 | "\n", 2171 | "If you see this message, it means the renderer has not been properly enabled\n", 2172 | "for the frontend that you are using. For more information, see\n", 2173 | "https://altair-viz.github.io/user_guide/troubleshooting.html\n" 2174 | ] 2175 | }, 2176 | "execution_count": 24, 2177 | "metadata": {}, 2178 | "output_type": "execute_result" 2179 | } 2180 | ], 2181 | "source": [ 2182 | "alt.Chart(pd.DataFrame(enumerate(bbc_training_losses), columns=[\"epoch\", \"training_loss\"])).mark_bar().encode(x=\"epoch\", y=\"training_loss\")" 2183 | ] 2184 | }, 2185 | { 2186 | "cell_type": "markdown", 2187 | "metadata": {}, 2188 | "source": [ 2189 | "Let's take a look at the reduced dimensionality paragraph vectors." 2190 | ] 2191 | }, 2192 | { 2193 | "cell_type": "code", 2194 | "execution_count": null, 2195 | "metadata": {}, 2196 | "outputs": [], 2197 | "source": [ 2198 | "bbc_2d = pca_2d(bbc_model.paragraph_matrix.data, bbc_df.group.to_numpy())\n", 2199 | "chart = alt.Chart(bbc_2d).mark_point().encode(x=\"x\", y=\"y\", color=\"group\")\n", 2200 | "# Uncomment to print chart inline, but beware it will inflate the notebook size\n", 2201 | "# chart" 2202 | ] 2203 | }, 2204 | { 2205 | "cell_type": "markdown", 2206 | "metadata": {}, 2207 | "source": [ 2208 | "`2-component PCA, explains 2.65% of variance`\n", 2209 | "\n", 2210 | "![](./img/bbc_pca_all_topics.png)" 2211 | ] 2212 | }, 2213 | { 2214 | "cell_type": "markdown", 2215 | "metadata": {}, 2216 | "source": [ 2217 | "These results aren't great, but we can see the beginnings of separation. If we look at just two topics it becomes more obvious." 2218 | ] 2219 | }, 2220 | { 2221 | "cell_type": "code", 2222 | "execution_count": null, 2223 | "metadata": {}, 2224 | "outputs": [], 2225 | "source": [ 2226 | "chart = alt.Chart(bbc_2d[bbc_2d[\"group\"].isin([\"sport\", \"business\"])]).mark_point().encode(x=\"x\", y=\"y\", color=\"group\")\n", 2227 | "# Uncomment to print chart inline, but beware it will inflate the notebook size\n", 2228 | "# chart" 2229 | ] 2230 | }, 2231 | { 2232 | "cell_type": "markdown", 2233 | "metadata": {}, 2234 | "source": [ 2235 | "![](./img/bbc_pca_business_sport.png)" 2236 | ] 2237 | }, 2238 | { 2239 | "cell_type": "markdown", 2240 | "metadata": {}, 2241 | "source": [ 2242 | "Likewise we can see sorting by similarity produces reasonable, but not ideal, results." 2243 | ] 2244 | }, 2245 | { 2246 | "cell_type": "code", 2247 | "execution_count": 27, 2248 | "metadata": {}, 2249 | "outputs": [ 2250 | { 2251 | "data": { 2252 | "text/html": [ 2253 | "
\n", 2254 | "\n", 2267 | "\n", 2268 | " \n", 2269 | " \n", 2270 | " \n", 2271 | " \n", 2272 | " \n", 2273 | " \n", 2274 | " \n", 2275 | " \n", 2276 | " \n", 2277 | " \n", 2278 | " \n", 2279 | " \n", 2280 | " \n", 2281 | " \n", 2282 | " \n", 2283 | " \n", 2284 | " \n", 2285 | " \n", 2286 | " \n", 2287 | " \n", 2288 | " \n", 2289 | " \n", 2290 | " \n", 2291 | " \n", 2292 | " \n", 2293 | " \n", 2294 | " \n", 2295 | " \n", 2296 | " \n", 2297 | " \n", 2298 | " \n", 2299 | " \n", 2300 | " \n", 2301 | " \n", 2302 | " \n", 2303 | " \n", 2304 | " \n", 2305 | " \n", 2306 | " \n", 2307 | " \n", 2308 | " \n", 2309 | " \n", 2310 | " \n", 2311 | " \n", 2312 | " \n", 2313 | " \n", 2314 | " \n", 2315 | " \n", 2316 | " \n", 2317 | " \n", 2318 | " \n", 2319 | " \n", 2320 | " \n", 2321 | " \n", 2322 | " \n", 2323 | " \n", 2324 | " \n", 2325 | " \n", 2326 | " \n", 2327 | " \n", 2328 | " \n", 2329 | " \n", 2330 | " \n", 2331 | " \n", 2332 | " \n", 2333 | " \n", 2334 | " \n", 2335 | " \n", 2336 | " \n", 2337 | " \n", 2338 | "
doc_idsimilaritytext
001.000000Claxton hunting first major medal British hurdler Sarah Claxton is confident she can win her fi...
37370.504319Radcliffe proves doubters wrong This won't go down as one of the greatest marathons of Paula's ...
41410.499603Radcliffe enjoys winning comeback Paula Radcliffe made a triumphant return to competitive runni...
154515450.499484Search wars hit desktop PCs Another front in the on-going battle between Microsoft and Google i...
126612660.490500Student 'inequality' exposed Teenagers from well-off backgrounds are six times more likely to g...
19190.442955Edwards tips Idowu for Euro gold World outdoor triple jump record holder and BBC pundit Jonatha...
3483480.430447Italy aim to rattle England Italy coach John Kirwan believes his side can upset England as the ...
2512510.429918Ferguson rues failure to cut gap Boss Sir Alex Ferguson was left ruing Manchester United's fail...
24240.429485El Guerrouj targets cross country Double Olympic champion Hicham El Guerrouj is set to make a r...
4644640.412518Henin-Hardenne beaten on comeback Justine Henin-Hardenne lost to Elena Dementieva in a comeback...
\n", 2339 | "
" 2340 | ], 2341 | "text/plain": [ 2342 | " doc_id similarity \\\n", 2343 | "0 0 1.000000 \n", 2344 | "37 37 0.504319 \n", 2345 | "41 41 0.499603 \n", 2346 | "1545 1545 0.499484 \n", 2347 | "1266 1266 0.490500 \n", 2348 | "19 19 0.442955 \n", 2349 | "348 348 0.430447 \n", 2350 | "251 251 0.429918 \n", 2351 | "24 24 0.429485 \n", 2352 | "464 464 0.412518 \n", 2353 | "\n", 2354 | " text \n", 2355 | "0 Claxton hunting first major medal British hurdler Sarah Claxton is confident she can win her fi... \n", 2356 | "37 Radcliffe proves doubters wrong This won't go down as one of the greatest marathons of Paula's ... \n", 2357 | "41 Radcliffe enjoys winning comeback Paula Radcliffe made a triumphant return to competitive runni... \n", 2358 | "1545 Search wars hit desktop PCs Another front in the on-going battle between Microsoft and Google i... \n", 2359 | "1266 Student 'inequality' exposed Teenagers from well-off backgrounds are six times more likely to g... \n", 2360 | "19 Edwards tips Idowu for Euro gold World outdoor triple jump record holder and BBC pundit Jonatha... \n", 2361 | "348 Italy aim to rattle England Italy coach John Kirwan believes his side can upset England as the ... \n", 2362 | "251 Ferguson rues failure to cut gap Boss Sir Alex Ferguson was left ruing Manchester United's fail... \n", 2363 | "24 El Guerrouj targets cross country Double Olympic champion Hicham El Guerrouj is set to make a r... \n", 2364 | "464 Henin-Hardenne beaten on comeback Justine Henin-Hardenne lost to Elena Dementieva in a comeback... " 2365 | ] 2366 | }, 2367 | "execution_count": 27, 2368 | "metadata": {}, 2369 | "output_type": "execute_result" 2370 | } 2371 | ], 2372 | "source": [ 2373 | "most_similar(bbc_model.paragraph_matrix.data, bbc_df, 0, n=10)" 2374 | ] 2375 | }, 2376 | { 2377 | "cell_type": "markdown", 2378 | "metadata": {}, 2379 | "source": [ 2380 | "Next steps\n", 2381 | "----------\n", 2382 | "\n", 2383 | "That's all for now! I honestly hope that was fun and educational (it was for me, anyway).\n", 2384 | "\n", 2385 | "But data science projects are notorious for never being finished. To carry this on, we could:\n", 2386 | "\n", 2387 | "- look for better hyperparameters, since the training loss remains quite high\n", 2388 | "- benchmark against `gensim` and Ilenic's PyTorch implementation; it should be very similar to the latter\n", 2389 | "- implement the inference step for new documents, which freezes the word and output matrices and adds a new column to the paragraph matrix\n", 2390 | "- use inferred paragraph vectors as the input for a topic classifier; looking at the business/sport plot above it could be quite successful\n", 2391 | "- try visualization with a better dimensionality reduction algorithm than PCA (I've used [LargeVis](https://arxiv.org/abs/1602.00370) in the past)" 2392 | ] 2393 | } 2394 | ], 2395 | "metadata": { 2396 | "kernelspec": { 2397 | "display_name": "Python 3", 2398 | "language": "python", 2399 | "name": "python3" 2400 | }, 2401 | "language_info": { 2402 | "codemirror_mode": { 2403 | "name": "ipython", 2404 | "version": 3 2405 | }, 2406 | "file_extension": ".py", 2407 | "mimetype": "text/x-python", 2408 | "name": "python", 2409 | "nbconvert_exporter": "python", 2410 | "pygments_lexer": "ipython3", 2411 | "version": "3.7.2" 2412 | } 2413 | }, 2414 | "nbformat": 4, 2415 | "nbformat_minor": 2 2416 | } 2417 | --------------------------------------------------------------------------------