{'fraction_non_alphanumeric': 0.03440136601044596, 'fraction_numerical': 0.009893531538770591, 'mean_word_length': 5.05258358662614, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Odor Descriptor Understanding through Prompting

Embeddings from contemporary natural language processing (NLP) models are commonly used as numerical representations for words or sentences. However, odor descriptor words, like"leather"or"fruity", vary significantly between their commonplace usage and their olfactory usage, as a result traditional methods for generating these embeddings do not suffice. In this paper, we present two methods to generate embeddings for odor words that are more closely aligned with their olfactory meanings when compared to off-the-shelf embeddings. These generated embeddings outperform the previous state-of-the-art and contemporary fine-tuning/prompting methods on a pre-existing zero-shot odor-specific NLP benchmark.


Introduction
Word embeddings from NLP models contain semantic knowledge that can be used across disparate tasks. However, in certain contexts, simply using the hidden layer activations for a particular word or phrase may not extract the desired knowledge from the NLP model. This is the case for odor descriptors, where their meanings in olfaction differ from everyday-use meanings.
Most NLP models are trained on general corpora and so their internal representations for words represent the most generalized context a word appears in. For example, in everyday speech "leather" refers to the material from which certain clothes are made of, or perhaps the tough, textured "leathery" feel of that material. This means that the off-the-shelf NLP model embedding for "leather" will likely be similar to words like "jacket", "rugged" or "hide". Though the term "leather" in olfaction refers to the scent of that material, it is perceptually similar to seemingly unrelated words like "musk" or "amber"[5]. The connotations in odor are abstract and aesthetic, and so are hard to pin down numerically. Overall though, the embeddings for odor descriptors in similar categories (take for example "apple", "fruit", and "peachy") should be closer to each other than the embeddings for words in dissimilar categories (like "gasoline").
In practice, this means that the same procedures that previously resulted in useful embeddings for other domains may not function when applied to odor descriptors. To aggravate the issue, though odor may be a common topic of discussion, datasets specifically focused on odor [18] are small in comparison to the hundreds of terabytes of data contained in contemporary NLP datasets[4].

Previous Work
A variety of work on quantitative analysis has been conducted on odor descriptors [29]. One of the most innovative approaches to NLP embeddings in this space is "Predicting natural language descriptions of mono-molecular odorants" [14].
The researchers used the fasttext[9] model trained on Wikinews 1 to generate 300 dimensional embeddings for a set of 150 single-word descriptors across 58 molecules from the DREAM [17] and Dravnieks [12] odorant datasets.
In order to evaluate the generated word embeddings, the researchers proposed a zero-shot task where ratings on the 19 descriptors used in the DREAM dataset are used to predict the ratings on the 131 descriptor used in the Dravnieks dataset for the same molecule. Both sets of ratings are in the [0,100] range. A linear regression model from scikit-learn [22] is fit between the 19x300 and 131x300 embeddings, and then predicts the 131 Dravnieks ratings from the 19 DREAM ratings.
One caveat not mentioned in the original study is the difficulty in generating embeddings for multi-word or out-of-dictionary descriptors using fasttext. In order to get around this issue, the researchers manually cleaned the descriptor lists. Though the DREAM dataset contains ratings on both "urinous" and "cat urine", both of these descriptors are simplified to "urine", which is within the dictionary for fasttext. Some descriptors, like "cleaning fluid" were removed altogether from the DREAM dataset.
As a result, though the original task described is a 19 to 131 rating prediction task, the full DREAM dataset is 146 descriptors. For the rest of this paper, the complete 19x146 descriptor task will be referred to as the full-descriptor task, and the previously described 19x131 task will be referred to as the single-word task.

Our Work
The contributions of our paper are as follows: Firstly, we highlight the need for odor-specific techniques of embedding generation, which contextualize the embedding to the olfactory space, in comparison with off-the-shelf methods which instead reflect the everyday-use meaning. Secondly, we provide two such techniques that better capture the olfactory connotations of these words, outperforming previous work and a variety of contemporary methods. For future researchers, our state-of-the-art method and the resultant embedding prompts are open-source 2 .

Randomized Baseline
In order to provide a baseline to these tasks, we generated random embeddings of dimension = 300 for each of the 150 descriptors. Fitting the linear regression model across these random vectors resulted in a score of .25 on the single-word task and a score of .26 on the full-descriptor task. Increasing the dimensionionality of these vectors to did not result in an increase in score.

Advances in NLP
Many larger and more powerful models have been developed since fasttext's release.
Though cutting-edge models like LaMDA [26] and GPT-3 [10] have resulted in impressive scores across a variety of natural language benchmarks, these models may be prohibitively expensive to train for the average researcher. Though BERT [11], a moderate-sized transformer [27] model, is nearly 3 years old, it strikes a balance between performance and resource-usage. In this case the publicly available BERT-large-uncased from Hugging Face's Transformers [28] is powerful enough while still feasibly trained within our budget.

Simple Approaches with BERT
A trivial approach to generate word embeddings is to use BERT's wordpiece dictionary. To extract the wordpiece embedding for "flowery", the descriptor is fed into BERT's tokenizer and split into "flow##" and "##ery". Averaging across the vector representations of these two wordpieces in BERT's pretrained dictionary provides an embedding for "flowery".
A more in-depth approach is to leverage the hidden layer embeddings for the isolated descriptors. Though BERT is a contextual model, it is possible to generate word embeddings for the odor descriptors without a context. To do this, the descriptor of interest ("flowery") is fed into the model, and the averaged hidden layer activations are used as 1024 dimensional embeddings. For the rest of the paper, the layer from which to extract activations is treated as a hyperparameter.

Context Development
There have been numerous techniques developed for generating contexts, now called prompts, in modern NLP research, ranging from human generated guesses [24] to fine-tuning approximate contexts [21]. Usually, these prompts take the form of words or tokens surrounding a [blank] where the descriptor of interest is substituted, but sometimes the prompts are represented purely as differentiable vectors [20], which are fed directly into the model's hidden layers.
We leveraged a variety of different approaches, not all of which were successful. For elaboration on these unsuccessful techniques, see the "Failed Approaches" section in the appendix. We present two successful approaches: decent results with human generated prompts, and a new state-of-the-art on the aforementioned benchmark using a prompt mining technique.

Human Generation
Human generated prompts involve brainstorming domain-specific contexts for the descriptor of interest. Though this method is not rigorous or rooted in statistical theory, it is simple to implement and computationally inexpensive. For the task of embeddings in the odor space, example human generated prompts are "[blank] scent" or "smells like [blank]". Another benefit of this method is that no corpus needs to be collected and there is no additional training or fine-tuning of the model, so the computational cost is low.

Corpus for Mining
Prompt mining [16] involves searching domain relevant corpora for the contexts surrounding the descriptors of interest. For the corpora from which to mine contexts, we used the GoodScents[3] perfume materials database and Leffingwell PMP 2001 [2] database. These catalogs consist of lists of chemicals with short olfactory descriptions, generated by experts.
Prior to any cleaning, these two corpora totalled 650,000 words when combined. The dataset required standardization, as some chemical descriptions consisted of lists of descriptors ("musky", "sweet", "chalky") and others were closer to full sentences ("Ambrofix is a highly powerful, highly substantive and highly stable ambery note for use in all applications"). We aimed to isolate and list the odor descriptors: in other words, "musky", "sweet" and "chalky" would all be separated, whereas "highly powerful, highly substantive and highly stable ambery note" would be kept together as a multi-word descriptor.
In order to canonicalize the input, we transformed the dataset into a comma separated list of word chunks, parsed using spaCy [15]. This resulted in around 40k unique total descriptors. The median and mode word occurrence frequency was 1, but the mean word occurence frequency was around 10.
Though a large number of descriptors appear only once, when we removed all these singleton descriptors, only 7% of the total dataset was discarded. The curve of the cumulative sum suggests that there is a relatively small set of descriptors that the authors of these datasets use frequently, and they reach for niche descriptors only occasionally.
For further cleanup, we then merged descriptors if their edit distances and embeddings were close enough ("chocolatey" and "chocolate"). We chose the canonical form of the pair based on frequency. From there, we had a dataset of around 2,000 unique descriptors, ready for mining.

Mining Algorithm
To mine the prompt, we used a k-beam search on the generated corpus. The algorithm starts initially with an empty prompt ("[blank]"), and then for each beam, a random descriptor from the corpus is selected, weighted based on frequency. This descriptor is then added arbitrarily as either a new suffix or prefix to the prompt. Each generation contains k beams (75 in our trials), and at subsequent iterations, only the top k most promising beams are kept. The beams are evaluated based on their scores averaged between the single-word and fulldescriptor tasks. This beam search works recursively, so that in the second and subsequent generations many potential prompts are explored (75*75=5625 in our trials).

Results
When using the hidden layer activations for the unprompted descriptor words alone, BERT-large-uncased achieves a score of .44 on the single-word task, slightly lower than the older fasttext model, and a score of .39 on the fulldescriptor task (hidden layer = 6). The most successful human generated prompt was "essence [blank] flavored" (hidden layer = 12), which scored .46 on the single-word task and .49 on the full-descriptor task, improving on the off-the-shelf BERT model without adding significant computational resources.
For our mined prompt, the k-beam search ran for 25 generations, though the score did not improve after the 14th generation, producing the best prompt of "many woody fresh butter popcorn woody orange biscuit rubbery [blank] intense garlic woody comments warm evaluation comments umami grape rain one"" (hidden layer = 11) with a score of .55 on the single-word task and a score of .56 on the full-descriptor task.  For the breakdown of improvement by descriptor, see supplementary information. For a summary, Table 3 contains the descriptors with the largest gains and losses.
For a visual comparison, we present the embedding spaces of various techniques ( Figure 6) reduced to 2 dimensions through principal component analysis (PCA). To highlight the shift in the embedding space, "leather" is charted in green. Five odor descriptors related to "leather" are charted in blue ("musky", "gasoline", "smoky", "amber", "musk"). Five additional words which are similar in the common usage to "leather" but not related to odor are included as negatives and are charted in orange ("jacket", "rugged", "hide", "material", "tanning"").
BERT with the mined prompt is the only embedding space where the negatives are on average further from "leather" than the positives, using Euclidean distance. To measure the spread of the embedding space, the average distance from each embedded point to the centroid of all points is also provided in Table  4. As can be seen in the PCA figures, the embedding space for BERT without a prompt is more spread out than the other two methods. Embedding space is spread out, and the central cluster is disorganized, with most negatives close to "leather".
(c) Embedding space for BERT with the mined prompt.
Embedding space is relatively, neither too dense nor too sparse.

Model
Mean  Table 4: Quantitative comparison of embedding spaces of fasttext and our two methods.

Conclusion
Mining a prompt through a k-beam search on a domain specific dataset outperforms the randomized baseline and the previous state-of-the-art. Though the more recent BERT model struggled off-the-shelf, careful selection of a prompting algorithm meant large gains on the single-word task and a strong score on the full-descriptor task. It is also interesting to note that even using a simple human generated prompt produces decent results. The best prompt we found ("many woody fresh butter popcorn woody orange biscuit rubbery [blank] intense garlic woody comments warm evaluation comments umami grape rain one") is nonsensical and contains duplicate words, as well as words not obviously related to olfaction, yet it outperforms human generated prompts containing tokens more superficially related to odor. Further research into why seemingly irrelevant words function well as prompt tokens is necessary, but it may suffice to imagine that what humans consider relevant differs from what has been encoded into textual usage as relevant: the deeper meaning eludes a surface level analysis.
We offer a tested context for researchers in the odor space looking to generate numerical representations for odor words. For example, researchers often need to unify descriptions in list form ("musky, sweet, chalky") with descriptions in plaintext ("Ambrofix is a highly powerful. . . ") or in rating form ("musky: 50, flowery: 39") while preserving each description's meaning: future researchers can use our embeddings to convert all these different descriptions into vectors. Another application we are particularly interested in seeing is determining a core set of odor descriptors on which olfaction experts rate new odorants, perhaps generating using a clustering approach on the descriptor embeddings.

Additional Considerations
This paper was affected by the limited size of odor specific NLP corpora. As stated before, though other domains have datasets consisting of billions of words[4], we struggled to collect half a million words. Even then, this dataset came out of private and confidential catalogs, meaning distribution to other researchers is infeasible.
However, there are actually large repositories of odor descriptions online, in the form of perfume discussion forums like Fragrantica [7] and Basenotes [6]. Unfortunately, these are legally guarded, and contain programmatic blocks against web crawlers. In practice, this content may be less specific than Goodscents or Leffingwell, as they contain freeform writing by untrained contributors, and the olfactory descriptions are mixed in among non-odor discussion about sales, packaging and branding. However, these datasets are orders of magnitude larger than the chemical repository datasets, and with some cleaning, these comments and reviews would be highly useful to future researchers.
Finally, the evaluation benchmark was limited in scope. It involved only 150 descriptors, out of thousands, rated on a small number of examples. For a more realistic odor-specific NLP task, something akin to the Microsoft Research Paraphrase Corpus [19] for olfaction could be created. For evaluation, a model would be tasked to determine whether or not two olfactory descriptions were describing the same odorant or different odorants. The data required to generate thousands of such examples for this task is already available on the internet, and only needs to be cleaned up and made publicly available. Without this, NLP for olfaction will unnecessarily remain a low data domain.
6 Appendix 6.1 Attached Extra Files improvement by desc.csv

Failed Approaches
The two presented techniques, human generated prompts and mined prompts, were only a subset of all techniques we applied to this benchmark. We actually implemented other techniques which resulted in failure. This section enumerates the other techniques and discusses their costs and benefits, especially with regard to their computational cost and ease of implementation, so that future researchers can decide on techniques based on their resources.
Firstly, the most obvious method to improve on BERT off-the-shelf is to finetune the weights of the BERT model. The official BERT GitHub [1] contains a script to fine-tune the model, meaning there was little to no implementation work. However when improvements on the BERT MLM task using our dataset did not translate to improvements on the descriptor prediction benchmark, it was unclear as to whether our gathered dataset was low quality, or whether a different training technique was necessary. In addition, because a single trial in the hyperparameter tuning process done through Vizier [13] may involve 10-100k training steps, this method is costly, and we needed to spin up a 64-core Cloud TPU[8]. One source of our issues may have been that the corpus involved in pre-training BERT is on the scale of billions of words [11], while finding a corpus of even a million words is infeasible for odor right now; a larger corpus may have been necessary to get better results from fine-tuning.
When fine-tuning did not pan out, we looked into prompting as a more flexible and less expensive method. We first attempted human generated prompts, which brought good results, but we looked to previous work to improve further. None of these techniques require a training dataset, and we were able to use the benchmark score as the direct evaluation metric.
We attempted to tune a prompt of fixed size consisting of tokens sampled from BERT's vocabulary, originally presented by "AutoPrompt: Eliciting knowledge from language models..." [25] and then optimized in "Learning How to Ask: Querying LMs..." [23]. Essentially, a number of tokens are selected as the initial prompt, and then the prompt tokens are permuted and replaced over the course of training. We attempted to use the techniques described in both papers, and while the only hyperparameter was prompt length, their source codes did require a decent amount of modification to work with our project. In the end, we did not get usable results from either approach.
We also tried tuning a vector prompt of fixed size, based on work presented in "The Power of Scale for Parameter-Efficient Prompt Tuning" [20]. This technique leverages backpropagation to train a prompt vector fed directly into the model's transformer layers. This involved more hyperparameters, requiring tuning through Vizier. As above, using this technique did not improve meaningfully on BERT off-the-shelf.  Table 5: Cost analysis of the fine-tuning and prompting methods we explored.
Future researchers would benefit from following Occam's razor and leveraging the simplest approach that meets their needs first before exploring others.