C AN A F RUIT F LY L EARN W ORD E MBEDDINGS ?
Anonymous authors
Paper under double-blind review
A BSTRACT
The mushroom body of the fruit ﬂy brain is one of the best studied systems in neuroscience.
At its core it consists of a population of Kenyon cells, which receive inputs from multiple sensory modalities.
These cells are inhibited by the anterior paired lateral neuron, thus creating a sparse high dimensional representation of the inputs.
In this work we study a mathematical formalization of this network motif and apply it to learning the correlational structure between words and their context in a corpus of unstructured text, a common natural language processing (NLP) task.
We show that this network can learn semantic representations of words and can generate both static and context-dependent word embeddings.
Unlike conventional methods (e.g., BERT, GloVe) that use dense representations for word embedding, our algorithm encodes semantic meaning of words and their context in the form of sparse binary hash codes.
The quality of the learned representations is evaluated on word similarity analysis, word-sense disambiguation, and document classiﬁcation.
It is shown that not only can the fruit ﬂy network motif achieve performance comparable to existing methods in NLP, but, additionally, it uses only a fraction of the computational resources (shorter training time and smaller memory footprint).
I NTRODUCTION
Deep learning has made tremendous advances in computer vision, natural language processing and many other areas.
While taking high-level inspiration from biology, the current generation of deep learning methods are not necessarily biologically realistic.
This raises the question whether biological systems can further inform the development of new network architectures and learning algorithms that can lead to competitive performance on machine learning tasks or offer additional insights into intelligent behavior.
Our work is inspired by this motivation.
We study a well-established neurobiological network motif from the fruit ﬂy brain and investigate the possibility of reusing it for solving common machine learning tasks in NLP.
We consider this exercise as a toy model example illustrating the possibility of “reprogramming” of naturally occurring algorithms and behaviors (clustering combinations of input stimuli from olfaction, vision, and thermo-hydro sensory system) into a target algorithm of interest (learning word embeddings from raw text) that the original biological organism does not naturally engage in.
The mushroom body (MB) is a major area of the brain responsible for processing of sensory information in fruit ﬂies.
It receives inputs from a set of projection neurons (PN) conveying information from several sensory modalities.
The major modality is olfaction (Bates et al., 2020), but there are also inputs from the PN responsible for sensing temperature and humidity (Marin et al., 2020), as well as visual inputs (Vogt et al., 2016; Caron et al., 2020).
These sensory inputs are forwarded to a population of approximately 2000 Kenyon cells (KCs) through a set of synaptic weights (Li et al., 2020).
KCs are reciprocally connected through an anterior paired lateral (APL) neuron, which sends a strong inhibitory signal back to KCs.
This recurrent network effectively implements winner-takesall competition between KCs, and silences all but a small fraction of top activated neurons (Dasgupta et al., 2017).
This is the network motif that we study in this paper; its schematic is shown in Fig.
KCs also send their outputs to mushroom body output neurons (MBONs), but this part of the MB network is not included into our mathematical model.
Behaviorally, it is important for a fruit ﬂy to distinguish sensory stimuli, e.g., different odors.
If a fruit ﬂy senses a smell associated with danger, it’s best to avoid it; if it smells food, the fruit ﬂy might want to approach it.
The network motif shown in Fig.
1 is believed to be responsible for
[Figure]
clustering sensory stimuli so that similar stimuli elicit similar patterns of neural responses at the level of KCs to allow generalization, while distinct stimuli result in different neural responses, to allow discrimination.
Importantly, this biological network has evolved to accomplish this task in a very efﬁcient way.
In computational linguistics there is a long tradition (Harris, 1954) of using distributional properties of linguistic units for quantifying semantic similarities between them, as summarized in the famous quote by JR Firth: “a word is characterized by the company it keeps” (Firth, 1957).
This idea has led to powerful tools such as Latent Semantic Analysis (Deerwester et al., 1990), topic modelling (Blei et al., 2003), and language models like word2vec (Mikolov et al., 2013a), GloVe (Pennington et al., 2014), and, more recently, BERT (Devlin et al., 2018) which relies on the Transformer model (Vaswani et al., 2017).
Speciﬁcally word2vec models are trained to maximize the likelihood of a word given its context, GloVe models utilize global word-word co-occurence statistics, and BERT uses a deep neural network with attention to predict masked words (and the next sentence).
As such, all these methods utilize the correlations between individual words and their context in order to learn useful word embeddings.
In our work we ask the following question: can the correlations between words and their contexts be extracted from raw text by the biological network of KCs, shown in Fig. 1?
Further, how do the word representations learned by KCs differ from those obtained by existing NLP methods?
Although this network has evolved to process sensory stimuli from olfaction and other modalities and not to “understand” language it uses a general purpose algorithm to embed inputs (from different modalities) into a high dimensional space with several desirable properties, which we discuss below.
Our approach relies on a recent proposal that the recurrent network of mutually inhibited KCs can be used as a “biological” model for generating sparse binary hash codes for the input data presented at the projection neuron layer (Dasgupta et al., 2017).
It was argued that a matrix of random weights projecting from PN layer into the KCs layer leads to the highly desirable property of making the generated hash codes locality sensitive, i.e., placing similar inputs close to each other in the embedding space and pushing distinct stimuli far apart.
A subsequent study (Ryali et al., 2020) has demonstrated that the locality sensitivity of the hash codes can be signiﬁcantly increased, compared to the random case, if the matrix of weights from PN to KCs is learned from data.
The learning is unsupervised.
Biologically, there is an ongoing debate in the neuroscience community regarding whether these projections are random.
For instance, (Caron et al., 2013) argues for the random model, while (Zheng et al., 2020) presents evidence of the non-random structure of this network, which is related to the frequency of presented odors.
Since the goal of our work is to build a useful AI system and not mimic every detail of the biological system, we adopt the data-driven synaptic weight strategy even if fruit ﬂies may use random projections.
As is clearly demonstrated in (Ryali et al., 2020), learned synapses lead to better performance.
Our main contributions in this work are the following:
Inspired by the fruit ﬂy network, we propose an algorithm that makes it possible to generate binary (as opposed to continuous) word embeddings for words and their context.
We systematically evaluate the performance of this algorithm on word similarity task, word-sense disambiguation, and document classiﬁcation.
We demonstrate that our binary embeddings result in tighter and better separated clusters of concepts compared to continuous GloVe embeddings, and stand in line with clustering properties of binarized versions of GloVe.
We show that training the fruit ﬂy network requires an order of magnitude smaller compute time than training the classical NLP architectures, like BERT, at the expense of relatively small decrease in classiﬁcation accuracy.
L EARNING A LGORITHM
Consider a training corpus.
Each sentence can be decomposed into a collection of w -grams of consecutive words.
If the word tokens come from a predeﬁned vocabulary of size N voc , the input to the algorithm is a vector of size 2 N voc .
This vector consists of two blocks: the context (the ﬁrst N voc elements), and the target (the remaining N voc elements); see Fig.
In this work w is assumed to be an odd integer, and the target word is assumed to be the center of the w -gram.
The target word
Apple stock rises on optimism for the new IPhone.
[Figure]
is one-hot encoded in the target block, and the context words are binary encoded as a bag of words in the context block (no positional information is used).
The window w slides along the text corpus, and for each position generates a training vector v A
= { v Ai } 2 N voc i =1 , where the index A enumerates different w -grams, and index i enumerates positions in the context-target vector.
These training vectors are passed to the learning algorithm.
The goal of the algorithm is to learn correlations between the context and the target blocks.
2. M ATHEMATICAL F ORMULATION
Mathematically, the objective of the training algorithm is to distribute a set of context-target pairs among K buckets, so that similar pairs end up in similar buckets.
In order to achieve this, the learning algorithm takes two inputs: a set of training vectors v A ∈ { 0 , 1 } 2 N voc , and a vector of occurrence probabilities p
= { p i =
f
( i mod N voc ) } 2 N voc i =1 ∈ R 2 N voc , where f j is the probability of observing word j in the training corpus 1 .
The learning can be formalized as a minimization of the energy function deﬁned by
[Equation]
where
[Equation]
In this equation W ∈ R K × 2 N voc is a matrix of synaptic connections, given as W = { W µ } = { W µi } , projecting from PN layer (individual neurons in the layer are denoted by the index i ) to the
KC layer (individual neurons in the KC layer are denoted by the index µ ).
There are 2 N voc neurons in the PN layer and K neurons in the KC layer.
The inner product (cid:104) X , Y (cid:105) =
(cid:80) 2 N
voc
i =
1 X i
Y i is deﬁned as a contraction over index i of PN cells.
In the numerator of the energy function the binary encoded w -gram is divided by the probabilities of occurrences of individual words element-wise, so that the numerator can be written as
[Equation]
Probabilities p are calculated based on the frequencies of words in the training corpus.
The vocabulary contains N voc most frequent words in the corpus, thus all the elements of p i are non-zero and the element-wise division is well deﬁned.
Intuitively, the goal of the training algorithm is to adjust the weights of the neural network so that they are aligned with w -grams that are frequently present in the training corpus.
We rely on the assumption that semantically related w -grams share several “core” words, while a few individual words might be substituted by synonyms/antonyms.
The minimization of the energy function (1) is accomplished by the iterative update of the weights satisfying the following learning rule (Krotov &
Hopﬁeld, 2019; Ryali et al., 2020)
[Equation]
In this equation the activation function is equal to one for a maximally driven hidden unit (Kenyon cell), and is equal to zero otherwise
[Equation]
where
[Equation]
The learning rate is denoted by ε , and δ µ, ˆ µ is a Kronecker delta symbol.
2. B IO -H ASHING
After learning is complete the hash codes for the inputs can be generated in the following way.
Given the binary encoded w -gram v A ,
[Equation]
the top k of all KCs activations
[Equation]
This is a crude mathematical approximation of the biological computation performed by the PN–
KC–APL neural network (Dasgupta et al., 2017; Ryali et al., 2020).
An input v A generates an input current (cid:104) W µ , v A (cid:105) into the KC neurons using feedforward weights W µi .
The recurrent network of
KCs and the APL neuron silences all but a small fraction of KCs.
Those cells that remain active are assigned state 1 , while the rest of the KCs are assigned the inactive state 0 .
Notice, that equation (4) makes it possible to generate the hash codes for both individual words (static word embeddings like word2vec and GloVe) and phrases (similar to Transformer models).
In the static case, the input v A has all zeros in the context block and a one-hot encoded word in the target block.
In the context-dependent case, both blocks have binary encoded input words.
Importantly, both context-dependent and static embeddings are mapped into the same space of sparse binary hash codes (a vector of K elements, with k ones in it).
We show below that these hash codes capture semantic meaning of the target word and the context in which it is used.
For the rest of the paper we refer to the parameter k in equation (4) as the hash length .
In order to provide an intuition behind the learning algorithm deﬁned by the energy function (1) and weight update rule (2) and connect it to some of the existing methods in machine learning, consider the limit when all the words have equal probabilities in the training corpus, p i = 1 N voc . In this limit the energy function (1) reduces to the familiar spherical K -means clustering algorithm (Dhillon & Modha, 2001). In this limit the weights of each KC correspond to the centroids of the clusters of context-target vectors.
The hashing rule (4) assigns active state 1 to the k closest centroids (and inactive state 0 to the remaining ones), deﬁned with respect to cosine similarity distance.
In this simple limit the learning algorithm that we use can be viewed as a biologically plausible implementation of this classical algorithm.
For real datasets the probabilities of words are different, thus this correspondence does not hold.
Notice that division by the probability appears only in the expression for energy, but not in the deﬁnition of ˆ µ in equation (1).
Equivalently, division by p i appears in the second bracket of equation (2), but not in the argument of the activation function g [ x µ ] .
Thus, in the general case (for different word probabilities p i ) our algorithm is not equivalent to spherical
K -means on context-target vectors rescaled by the probabilities.
Rather, in the general case, the closest centroid is found for a given context-target vector (via deﬁnition of ˆ µ in equation (1) - no p i involved), but the “updates of the position” of that centroid are computed by enhancing the contributions of rare words (small p i ) and suppressing the contributions of frequent words (large p i ).
Empirically, we have found that division by the probabilities improves performance of our method compared to the case of spherical K -means (when the factor 1 / p is removed from the algorithm).
The KC network shown in Fig. 1 was trained on the OpenWebText Corpus (Gokaslan & Cohen, 2019), which is a 32 GB corpus of unstructured text containing approximately 6B tokens.
The details of the training protocols and the hyperparameters are reported in section 6 in the supplement.
3. S TATIC W ORD E MBEDDINGS E VALUATION
Our aim here is to demonstrate that the sparse embeddings obtained by the fruit ﬂy network motif are competitive with existing state-of-the-art word embeddings such as GloVe (Pennington et al., 2014) and word2vec (Mikolov et al., 2013a) and commonly used binarization tools for these continuous embeddings.
We show this by evaluating the semantic similarity of static word embeddings.
Several common benchmark datasets are used: WS353 (Finkelstein et al., 2002), MEN (Bruni et al., 2014),
RW (Luong et al., 2013), SimLex (Hill et al., 2015), RG-65 (Rubenstein & Goodenough, 1965), Mturk (Halawi et al., 2012).
These datasets contain pairs of words with human-annotated similarity scores between them.
Following previous work (Tissier et al., 2019; Sokal, 1958), model similarity score for binary representations is evaluated as sim ( v 1 , v 2 ) = ( n 11 + n 00 )
/n , where n 11 ( n 00 ) is the number of bits in v 1 and v 2 that are both 1 ( 0 ), and n is the length of v 1 , 2 . Cosine similarity is used for real-valued representations. Spearman’s correlation coefﬁcient is calculated between this similarity and the human annotated score.
The results are reported in Table 1.
[Table]
We observe that our word embeddings demonstrate competitive performance compared to GloVe, but worse performance than word2vec. At the same time, our embeddings are binary, as opposed to GloVe and word2vec, which are represented by continuous vectors. Thus, it is more appropriate to compare them with commonly used binarized versions of the continuous embeddings.
Speciﬁcally, we compare the performance of fruit ﬂy embeddings with a number of state-of-the-art binarization methods such as: LSH/SimHash (Charikar, 2002)
(random contractive projections followed by binarization based on sign), RandExp (Dasgupta et al., 2017) (random expansive projections followed by k -winner take all binarization), ITQ (Gong & Lazebnik, 2011) (iterative quantization), SH (spectral hashing)
(Weiss et al., 2009), PCAH (Gong & Lazebnik, 2011) (PCA followed by binarization based on sign). The complete evaluation of all these methods for varying hash length is presented in Section 7; please see Tables 7, 8, 9 for binarization of pretrained GloVe, pretrained word2vec, and GloVe trained on OpenWebText.
In Table 7 we also include evaluation from NLB, “Near-Lossless
Binarization” (Tissier et al., 2019) (autoencoder-based binarization) for the hash lengths where those results are available.
Here we only present a short summary of those results for a speciﬁc (small) hash length k = 4 in Table 2. [Table] It is clear from Table 2 that fruit ﬂy embeddings outperform existing methods for word embedding discretization on WS353 and Mturk, and demonstrate second best result (after LSH binarization of word2vec) on MEN. In general (see Tables 7, 8, 9), we ﬁnd that fruit ﬂy embeddings are particularly powerful compared to existing methods at small hash lengths (see k = 4 , 8 in the aforementioned tables).
These results indicate that the fruit ﬂy network can learn meaningful binary semantic representations directly from raw text.
We also note that an added advantage of binary embeddings is that they require only a fraction (approx.
3%) of the memory footprint required for continuous word embeddings (assuming they have the same length), since a real value requires 32 -bits per vector element, whereas a boolean value requires only 1 -bit.
3. W ORD C LUSTERING
A nice aspect of binary embeddings is that they result in tighter and better separated clusters than continuous embeddings.
To evaluate this property for our method we started with hash codes for individual words and performed agglomerative clustering via complete link, using the cosine distance as the metric.
The clustering algorithm was terminated at 200 clusters (we experimented with possible choices of this parameter, such as 200 , 500 , 1000 , 2000 , 3000 , 5000 , and arrived at similar conclusions).
We repeated the same analysis for continuous GloVe, binarization of GloVe embeddings via autoencoder-like method (Tissier et al., 2019), and simple discretization method of GloVe when one declares the largest k elements of each word vector to be 1 and assigns 0 to the remaining elements (for k = 50 , 75 , 120 , 200 ).
The results for the inter-cluster similarity vs. intra-cluster similarity are shown in Fig.
3 (panel A).
It is clear from this scatter plot that the average distance between the points within a cluster is smaller (higher similarity) for all considered binary embeddings compared to GloVe embeddings.
At the same time, the distance between the closest clusters is larger or equal (smaller similarity) for the fruit ﬂy embeddings and naive discretizations with k <
≈ 120 . We also observe that the clusters lose detail (i.e., both intra- and inter-cluster similarity increases) as the binarization threshold gets higher (shown for Glove). However, our embeddings maintain a balance between intra- and inter-clustering similarity, and thus still capture ﬁne-grained cluster information.
For instance, inspecting the semantic structure of the clusters obtained this way, an example of the hierarchical clustering diagram (lower part of the tree containing 42 leaves) is shown in Fig.
3 (panel
B).
We clearly observe semantically coherent clusters resulting from the fruit
ﬂy word embeddings.
3. C ONTEXT -D EPENDENT W ORD E MBEDDINGS
Here, we evaluate the effectiveness of our fruit ﬂy inspired approach for contextual word embeddings, as opposed to static (or context-independent) embeddings from above.
We use the WiC (Pilehvar & Camacho-Collados, 2018) and SCWS (Huang et al., 2012) benchmarks for the evaluation of context-sensitive word embeddings for word sense disambiguation.
Both the datasets comprise pairs [Figure] of sentences that contain a target word , and the task is to determine whether the two target words share a similar semantic meaning in the corresponding contexts.
The WiC dataset is modeled as a binary prediction task, with 1 denoting that the target words have the same sense, and 0 indicating that they mean different things.
The SCWS dataset is modeled as a rank prediction task, since for each pair of sentences and target words, it reports the average human similarity scores (from
Amazon Mechanical Turkers per pair).
word in context 10 nearest neighbor words in the hash code space
[Figure]
Before presenting quantitative results, we qualitatively examine how the fruit ﬂy network performs on context sentence pairs for target words “apple” and “bank” in Fig.
We show the top q =nearest neighbor words for the context dependent target word.
These examples clearly indicate that the “correct” sense of the word has been found (“apple” the device manufacturer has different nearest neighbors from the fruit, and “bank” the ﬁnancial institution from the natural feature).
For the quantitative comparison, we contrast our method against contextual embeddings from
BERT (Devlin et al., 2018), GloVe (Pennington et al., 2014), word2vec (Mikolov et al., 2013a) and Word2Sense (Panigrahi et al., 2019).
For BERT we use the 768-dimensional embeddings from the uncased-large model, for GloVe and word2vec we use the 300-dimensional embeddings, and for Word2Sense we use the sparse 2250-dimensional pretrained embeddings.
Since BERT outputs contextual embeddings for each word in a sentence, we simply compute the cosine similarity between the embedding vectors for the target words for each pair of instances.
For GloVe/word2vec, we use a context window of size w centered at each of the target words and compute the average embedding for each window and compute the cosine similarity between the two window vectors.
Similar approach is used for Word2Sense, but the similarity between two embeddings is based on the Jensen-Shannon divergence (Panigrahi et al., 2019).
For the fruit ﬂy network, given the effectiveness of the top- q nearest neighbor words (as seen in Fig. 4), we devise a two component scoring function.
The ﬁrst component is the dot-product between the context-dependent hash codes for the two target words plus w length context blocks, denoted J dot .
The second is the number of common contextual nearest neighbors of the two target words among the top- q neighbors of each (scaled to be between 0 and 1), denoted J nn .
The ﬁnal score is given as J = α · J dot + (1 − α ) · J nn , where α ∈ [0 , 1] is a hyperparameter.
For all the methods, we predict a WiC pair to be positive if the score is above a threshold value θ .
For SCWS, the ranking is proportional to the scores above θ , with the rest scored as zero.
The hyperparameter θ is tuned for all the methods independently.
Finally, for a fair comparison, all methods use the same 20k vocabulary.
We report the performance of our context-dependent word embeddings for both SCWS and WiC in
Table 3 and Table 4, respectively.
For both benchmarks we report the results from a 5-fold crossvalidation study, where each fold (in turn) is used as a development set [Table] and the remaining four folds as the test set.
We select the optimal hyperparameters (including θ, α, q, k, w ) for all the methods using only the ﬁrst fold; no training is done since we evaluate only the pretrained embeddings.
The tables report the Spearman rank correlation on SCWS, and the accuracy on WiC.
[Table] [Table]
On SWCS (Table 3), we see that the context-independent embeddings (using w = 0 ) are better for GloVe, Word2Sense and our method, with word2vec yielding the best results.
The reason is that about 86.5% of the word pairs in SCWS are different words, and can be distinguished without looking at the context.
Unlike SCWS, the WiC benchmark uses the same target word (with only minor variations in some cases) in both contexts, and therefore a context-independent approach is not expected to perform well.
Indeed, on WiC (Table 4), we clearly observe that context-independent vectors ( w = 0 ) are not very good [Table] and our method, that uses the joint scoring function J combining both the hash code and nearest neighbor scores, is better than context-dependent GloVe ( w = 7 ), word2vec ( w = 5 ) and Word2Sense (also w = 7 ).
[Table]
were binarized into 256 and 512 bits. For our model, hash length 30 is used. For fair comparison, all models use the same vocabulary of 20k words.
3. D OCUMENT C LASSIFICATION
We also compare our binary embeddings with GloVe (Pennington et al., 2014), Word2vec (Mikolov et al., 2013b), BERT (Devlin et al., 2018) and Near-Lossless Binarization (Tissier et al., 2019) on document classiﬁcation tasks.
The benchmarks we use are 20 Newsgroups (20NewsGroups), Stanford Sentiment Treebank (Socher et al., 2013), WOS-11967(Kowsari et al., 2017) and TRECdatasets (Li & Roth, 2002).
The 20 Newsgroups dataset contains around 18,000 documents, partitioned evenly into 20 different groups; the Stanford Sentiment Treebank dataset contains movie reviews reﬂecting their sentiment as either positive or negative; WOS-11967 dataset containsdocuments with 35 categories which include 7 parents categories; and TREC-6 dataset consists of open-domain, fact-based questions divided into broad semantic categories.
We use the TextCNN (Kim, 2014) classiﬁer that uses all the different embeddings mentioned above.
For fair comparison, we use the same model parameters (e.g., kernel size, ﬁlter dimension) while testing different embeddings.
The results in Table 5 show how our sparse binary encodings are competitive with other methods. [Table]
C OMPUTATIONAL C OMPLEXITY
The computational complexity of our method can be evaluated by analyzing equations (2,3) for the weight updates.
In these equations v A is a sparse vector, which has only w non-zero elements in it.
Thus, for a minibatch of size | BS | , the computational complexity of evaluating the dot product with weights is K · w · | BS | .
Additionally, the argmax operation requires K · | BS | operations.
We will assume that the largest parameters in our model are the size of the corpus | A | ≈ 10 10 , and the size of the vocabulary N voc ≈ 10 4 − 10 5 .
Additionally we use large minibatches | BS | ≈ N voc .
Calculation of the second term in (2) requires O ( K · N voc ) operations in addition to K · w · | BS | operations for calculating the dot-product for each data point.
Since the algorithm has to go over the entire corpus, this computation needs to be repeated | A | / | BS | times per epoch.
Thus, the overall computational complexity of our method is O (cid:16) K · | A | ( w + N voc / | BS | ) (cid:17) ≈ K · | A | · w per epoch.
Thus, in the leading order it does not grow with the size of the vocabulary, which is a nice computational feature.
From the practical perspective, typical wall-clock training time and memory requirements per epoch are shown in Table 6.
As is shown in Fig.
5, accurate solutions are obtained after about 2 −epochs; improvements beyond that are relatively small.
Thus, our algorithm is capable of producing competitive models in a couple of hours.
Contrast this with approximately 24 hours training time for GloVe (Pennington et al., 2014); 4 days of training on 16 TPUs for BERT BASE ; and 4 days on 64 TPUs for BERT LARGE (Devlin et al., 2018)
(the last two numbers assume training corpus of size 250B tokens vs. 6B tokens considered in this paper).
The record breaking training time ofminutes for BERT requires the use of 1472 NVIDIA R (cid:13) V100 GPUs each with 32 GB of memory and a specialized DGX TM server architecture (Narasimhan, 2019). In our own experiments, we trained
GloVe embedding on OWT corpus using the same vocabulary of 20k words that we used for the fruit ﬂy embeddings.
The wall-clock training time was approximately 10 hours on 16 threads, see details in Section 10.
These are substantially larger computational resources than those required for training the fruit ﬂy network.
D ISCUSSION AND C ONCLUSIONS
In this work we asked the intriguing question whether the core computational algorithm of one of the best studied networks in neuroscience – the network of KCs in the fruit ﬂy brain – can be repurposed for solving a well deﬁned machine learning task, namely, learning word embeddings from text.
We have shown that, surprisingly, this network can indeed learn the correlations between the words and their context, and produce high quality word embeddings.
On the semantic similarity task the fruit ﬂy word embeddings outperform common methods for binarizing continuous SOTA word embeddings (applied to GloVe, word2vec, and GloVe trained on OWT) at small hash lengths.
On the word-in-context task the fruit ﬂy network outperforms GloVe by almost 3% , word2vec by more than 6% , but looses to BERT by 3 . 5% , see Table 4.
The small gap in classiﬁcation accuracy compared with BERT, however, is outweighed by the beneﬁt of requiring signiﬁcantly smaller computational resources to obtain these fruit ﬂy embeddings, as we have explained in Section 4, see Table 6.
We view this result as an example of a general statement that biologically inspired algorithms might be more compute efﬁcient compared with their classical (non-biological) counterparts, even if they slightly lose in terms of accuracy.
A PPENDIX A. T RAINING P ROTOCOLS AND H YPERPARAMETER C HOICES .
The fruit ﬂy network was trained on the OpenWebText Corpus (Gokaslan & Cohen, 2019), which is a 32 GB corpus of unstructured text containing approximately 6B tokens.
Individual documents were concatenated and split into sentences.
A collection of w -grams were extracted from each sentence by sliding a window of size w along each sentence from the beginning to the end.
Sentences shorter than w were removed.
The vocabulary was composed of N voc = 20000 most frequent tokens in the corpus.
Training was done for N epoch .
At each epoch all the w -grams were shufﬂed, organized in minibatches, and presented to the learning algorithm.
The learning rate was linearly annealed starting from the maximal value ε 0 at the ﬁrst epoch to nearly zero at the last epoch.
The training algorithm has the following hyperparameters: size of the KC layer K , window w , overall number of training epochs N epoch , initial learning rate ε 0 , minibatch size, and hash length k .
All models presented in this paper were trained for N epoch = 15 .
The optimal ranges of the hyperparameters are: learning rate is ε
≈ 10 − 4 − 5 · 10 − 4 ; K ≈ 200 − 600 ; w ≈ 9 − 15 ; minibatch size ≈ 2000 − 15000 ; hash length k is reported for each individual experiment.
A PPENDIX B. C OMPARISON WITH B INARIZED G LO V E AND WORD 2 VEC .
[Table]
[Table] [Table] [Table] [Table]
[Table]
[Table]
[Table] [Table]
[Table]
[Table] [Table]
[Table]
[Table]
[Table] [Table]
coefﬁcient is reported for common baselines that binarize GloVe (300d) embeddings together with our results.
Hyperparameter settings for our algorithm:
K = 400 , w = 11 .
Our aim here is to demonstrate that the fruit ﬂy word embeddings are competitive with existing state-of-the-art binarization methods applied to GloVe and word2vec embeddings.
We show this by evaluating the semantic similarity of static word embeddings, using several common benchmark datasets: WS353 (Finkelstein et al., 2002), MEN (Bruni et al., 2014), RW (Luong et al., 2013), SimLex (Hill et al., 2015), RG-65 (Rubenstein & Goodenough, 1965), and Mturk (Halawi et al., 2012).
These datasets contain pairs of words with human-annotated similarity scores between them.
Specif- ically, we compare with GloVe (Pennington et al., 2014) word embeddings 2 trained on Wiki and Gigaword 5, GloVe embeddings trained on OpenWebText Corpus (Gokaslan & Cohen, 2019) and word2vec embeddings 3 .
Since our representations are binary (in contrast to GloVe and word2vec), we binarize GloVe and word2vec embeddings and report their performance using a number of common hashing methods,
LSH/SimHash (Charikar, 2002)
(random contractive projections followed by binarization based on sign), RandExp (Dasgupta et al., 2017) (random expansive projections followed by k -winner take all binarization), ITQ (Gong & Lazebnik, 2011) (iterative quantization), SH (spectral hashing)
(Weiss et al., 2009), PCAH (Gong & Lazebnik, 2011) (PCA followed by binarization based on sign).
Where available, we include evaluation from NLB, “Near-Lossless Binarization” (Tissier et al., 2019)
(autoencoder-based binarization).
Following previous work (Tissier et al., 2019; Sokal, 1958), model similarity score for binary representations is evaluated as sim ( v 1 , v 2 ) =
( n 11 + n 00 )
/n , where n 11 ( n 00 ) is the number of bits in vand v 2 that are both 1 ( 0 ), and n is the length of v 1 , 2 .
Cosine similarity is used for real-valued representations.
The results are reported in Tables 7, 8 and 9.
For each dataset, we report performance across a range of hash lengths { 4 , 8 , 16 , 32 , 64 , 128 } .
For methods that incorporate randomness (LSH, RandExp, ITQ), we report the average across 5 runs.
ITQ, SH and PCAH in Tables 7 and 8 were trained using the top 400k most frequent words.
Table 9 compares our method to GloVe trained on OpenWebText (same dataset that our method is trained on) using the same vocabulary as our method uses. Our binary word embeddings demonstrate competitive performance compared to published methods for GloVe and word2vec binarization [Table] and our algorithm can learn meaningful binary semantic representations directly from raw text.
Importantly, our algorithm does not require training GloVe or word2vec embeddings ﬁrst before binarizing them. [Table] [Table] [Table]
[Table] [Table] The 300 d GloVe embeddings trained from scratch on the same OpenWebText dataset as our algorithm.  A PPENDIX C. D ETAILS OF T ECHNICAL I MPLEMENTATION .
From the practical perspective, efﬁcient implementation of the learning algorithm for the fruit ﬂy network requires the use of sparse algebra, atomic updates, and block-sparse data access.
Our algorithm is implemented in CUDA as a back-end, while python is used as an interface with the main functions.
The typical memory footprint of our approach is very small.
About 100 − 270 MB
GPU memory is allocated for the operators W µi , v A and temporary ﬁelds; while approximately 140 GB CPU memory is needed to store the input data, array of random numbers for shufﬂe operations and shufﬂed indices.
For GPU implementation, the model data is stored in the GPU’s memory, while the input data is stored in the CPU memory.
The parallelization strategy in our implementation is based on two aspects.
First, each minibatch of data is divided into smaller sub-minibatches which are processed on different GPUs.
Second, all the operations (dense-sparse matrix multiplications, arg max operation, and weight updates) are executed in parallel using multiple threads.  A PPENDIX D. Q UALITATIVE E VALUATION OF C ONTEXTUAL E MBEDDINGS .
In order to evaluate the quality of contextualized embeddings we have created an online tool, which we are planning to release with the paper, that allows users to explore the representations learned by our model for various inputs (context-target pairs).
For a given query the tool returns the word cloud visualizations for each of the four top activated Kenyon cells.
We show some examples of the outputs produced by this tool in Fig.
Each query is used to generate a bag of words input vector v A .
This vector is then used to compute the activations of KCs using (cid:68) W µ , v A (cid:69) .
Top four KCs with the highest activations are selected.
The corresponding four weight vectors are used to generate four probability distributions of individual words learned by those KCs by passing the weights through a softmax function.
For example, for one of those vectors with index µ , the probability distribution is computed as prob i =
SM ( W µi ) .
These probability distributions for the top four activated KCs are visualized as word clouds.
In computing the softmax only the target block of the weight vector was used (we have checked that using only the context block gives qualitatively similar word clouds).
Query: Senate majority leader discussed the issue with the members of the committee
Query: European Court of Human Rights most compelling cases
Query: Entertainment industry shares rise following the premiere of the mass destruction weapon documentary
The results indicate that the fruit ﬂy network indeed has learned meaningful representations.
Consider for example the ﬁrst query.
The sentence: “Entertainment industry shares rise following the premiere of the mass destruction weapon documentary” results in the four top activated KCs shown in Fig.
The top activated KC has the largest weights for the words “weapon”, “mass”, etc.
The second activated KC is sensitive to the words “market”, “stock”, etc.
This illustrates how the fruit ﬂy network processes the queries.
In this example the query refers to several distinct combinations of concepts: “weapon of mass destruction”, “stock market”, “movie industry”.
Each of those concepts has a dedicated KC responsible for it.
As one can see the responses are not perfect.
For example in this case one would expect to have the 4-th highest activated KC, which is responsible for the “movie industry” concept to have a higher activation than the 3-rd highest KC, which is responsible for the types of “weapons of mass destruction”.
But overall all the concepts picked by the KCs are meaningful and related to the query.
A PPENDIX E. D ETAILS OF G LO V E R ETRAINING
To directly compare our method to GloVe, we trained an uninitialized GloVe model on the same
OpenWebText corpus using the code provided by the original GloVe authors (Pennington et al., 2014) 4 .
This model was optimized to have the same vocab size as our model (the 20k most frequent tokens), used an embedding size of 300, and a window size of 15.
The model was trained foriterations at about 3 minutes, 20 seconds per iteration on 16 threads, resulting in the total training time of approximately 10 hours.
A PPENDIX F. R ELATED W ORK .
Our work builds on several ideas previously discussed in the literature.
The ﬁrst idea is that fruit ﬂy olfactory network can generate high quality hash codes for the input data in random (Dasgupta et al., 2017) and data-driven (Ryali et al., 2020) cases.
There are two algorithmic differences of our approach compared to these previous studies.
First, our network uses representational contraction, rather than expansion when we go from the PN layer to the KCs layer.
Second, (Dasgupta et al., 2017; Ryali et al., 2020) construct hash codes for data coming from a single modality (e.g., images, or word vectors), while the goal of the present paper is to learn correlations between two different “modalities”: target word and its context.
The second idea pertains to the training algorithm for learning the PN −→ KCs synapses.
We use a biologically plausible algorithm of (Krotov & Hopﬁeld, 2019) to do this, with modiﬁcations that take into account the wide range of frequencies of different words in the training corpus (we discuss these differences in section 2.1).
Also, similarly to (Dasgupta et al., 2017; Ryali et al., 2020)
the algorithm of (Krotov & Hopﬁeld, 2019) is used for learning the representations of the data, and not correlations between two types of data (context and target) as we do in this paper.