Repository navigation
Add text sampling - #304
Conversation
|
this looks great! |
|
Yes this looks awesome! |
| def str_presenter(dumper, data): | ||
| """configures yaml for dumping multiline strings | ||
| Ref: https://stackoverflow.com/questions/8640959/how-can-i-control-what-scalar-form-pyyaml-uses-for-my-data |
There was a problem hiding this comment.
shall we import this from utils?
There was a problem hiding this comment.
I'm pretty sure we have that in a few tabular data setup. I'll check that.
There was a problem hiding this comment.
Do you know a good setup to handle that?
I didn't find any nice solution except adding the additional import path or moving it to the chemnlp library.
Co-authored-by: Kevin M Jablonka <[email protected]>
| exclude_from_standard_tabular_text_templates = [ | ||
| "ames_mutagenicity", # because it is boolean target data | ||
| "bioavailability_ma_et_al", # because it is boolean target data | ||
| "blood_brain_barrier_martins_et_al", # because it is boolean target data | ||
| "chembl_v29", # text only, no SMILES | ||
| "moses", # SMILES only, has no target | ||
| "zinc", # SMILES only, has no target | ||
| ] |
There was a problem hiding this comment.
should we put this info into the meta.yaml files and not maintain it in two places? i.e. a meta.yaml file might tell itself if it is "ready" for the standard setup
There was a problem hiding this comment.
I added this to the to dos above!
Co-authored-by: Kevin M Jablonka <[email protected]>
Co-authored-by: Kevin M Jablonka <[email protected]>
Setup to sample text templates with the data.
Done:
data/ames_mutagenicity/meta.yaml.text_sampling/text_sampling.py.text_sampling/preprocess_kg.pyand the resulting data can be consumed bytext_sampling/text_sampling.pyw/o further modifications.data/tabularanddata/kg.docs/CONTRIBUTING.mdfor the new template setupmeta.yamland templating insertion.To do (can be moved to smaller PRs too):
exclude_from_standard_tabular_text_templates(indata/text_sampling/text_sampling.py) information to correspondingmeta.yamlfiles.Description of the new text template setup for the sampling
With the current setup you can:
meta.yamlfile, andExample text template 1 (mainly used for tabular data)
The molecule with the {SMILES__description} representation of {SMILES#} exhibits {mutagenic#no &NULL}{mutagenic__names__adjective} properties.SMILES__descriptiongets you the text from the description field of the SMILES identifier. The__dunder (double underscore) is used to indicate the levels in themeta.yamlfile.SMILES#gets you the data of the sampled SMILES row. The#is used to get the corresponding data.mutagenic#no &NULLgets you the data with#and recodes it. The recoding options are separated with a&. In this example the binary variablemutagenicthat can be0or1gets recoded tonoandNULL.NULLis a "reserved word" an indicates no value. Thus, thenogets added in front of themutagenic__names__adjectiveifmutagenic# == 0.mutagenic__names__adjectivegets you from theidmutagenicthe adjective names.Example text template 2 (mainly used for KG data)
The {node1_type#} {node1_name#|node1_smiles#} {rel1_type#} the {node2_type#} {node2_protein_names#} which {rel2_type#} the {node3_type#} {node3_name#}.node1_name#|node1_smiles#chains together two columns with|so they are jointly sampled for this position. In this case we sample from the name or the SMILES representation.node2_protein_namesthe column row can include several protein names also separated by a|, e.g.,Pyruvate dehydrogenase E1 component subunit beta, mitochondrial|PDHE1-Bwhich then samples fromPyruvate dehydrogenase E1 component subunit beta, mitochondrialorPDHE1-B.Example text templates 3 for multiple choice setups
Multiple choice setups are also supported. For this we need three components:
%multiple_choice_enum%2%aA1can be used to list the multiple choice enumerations, i.e.,1, 2, or 3,A or B, etc., The second%starts the multiple choice number sequence. Single integers and a range consisting of two integers separated by a-are supported to set the lower and higher number, e.g.,2-5will sample a value between those values including the boundaries for the answer options. The third%is used to subselect multiple choice enumerations, i.e.,afor lower case alphabetical enumerations,Afor upper case alphabetical, and1for numerical enumerations.mutagenic%is used to list the multiple choice enumerations with the corresponding possible answer options after the multiple choice enumerations, and%multiple_choice_resultis used to get the multiple choice enumeration of the answer, i.e.,1,c.Please pay attention to the
%symbol and its position as this is used to parse the different control elements from the text template.The sampling procedure incorporates a range of different multiple choice enumerations that are sampled randomly:
1, 2, 3, ...) and alphabetical (a, b, c, ...orA, B, C, ...) enumerations combined with(no suffix),.,.),), and:, to create a range of different multiple choice enumerations.If only the choices
0or1are available they will be recoded withFalseandTrue.Standard template
Example output:
Template for benchmarking
The benchmarking setup exports additional fields for the benchmarking setup, see the example below:
{"input":"Task: Please answer the multiple choice question below with 1 or 2.\nQuestion: Is the molecule with the SMILES representation of BrCBr Ames mutagenic?\nOptions:\n1.) False\n2.) True\nAnswer:","output":" 2","output_choices":["1","2"],"correct_output_index":"1"}Please have a look at the following section below about the general benchmarking template setup.
Example text templates 4 for flexible multiple choice setups
More flexible multiple choice setups are also supported. The standard multiple choice setup from "Example text templates 3 for multiple choice setups" is intended for features of molecules as those are deduplicated during the sampling process. In contrast, this flexible multiple choice setup also lets you use the molecule identifiers, e.g., SMILES, in the multiple choice options.
For this we only need to add one component to the previously outlined multiple choice format:
SMILEShas or has not the boolean variablepenetrate_BBBwe simply addSMILES%penetrate_BBB%as an enumeration placeholder for the possible options. With that the list of the multiple choice enumerations shows the SMILES data. Note that thepenetrate_BBB#not &NULLis needed because the sampling is based on the individual row and depending on ifpenetrate_BBBisTrueorFalsewe look for a different label because in the code we compare the sampled options to thepenetrate_BBBvalue of the row.Benchmarking text templates
There are two versions of text templates, i.e., one without the end-of-input token
<EOI>and those with:The
<EOI>token indicates the splitting position for the benchmarking export, i.e., everything before it will be written to theinputfield and everything afterwards to theoutputfield. Without<EOI>everything will be in thetextfield.In the current setup, you can switch with the
benchmarking_templatesflag of theTemplateSamplerclass between text templates with and without<EOI>.The filename scheme uses the split information for the export, i.e.,
train.jsonl,test.jsonl, etc., and if no split information is available this column will be set tofulland exported tofull.jsonl. With<EOI>the filename ends with_benchmark.jsonlinstead of.jsonl.Have a look at the
meta.yamlfile to see the corresponding structure there.