Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CoNLL-2003 dataset -Ner, Chunk and POS tagger #170

Closed
wants to merge 37 commits into from
Closed

Conversation

sbmaruf
Copy link
Contributor

@sbmaruf sbmaruf commented Jun 10, 2021

As the dataset is smaller, I only add two prompts for each of the tasks.

Two major issue to follow,

[ISSUE 1]:
After writing the template, on the right side, there is a sample shown in the app.
I see <p> tags inside the samples (from the inspect of the browser). I am not sure if this is because of HTML or not.

[ISSUE 2]:
After writing the template I don't see any error generated. But when I go the Prompted dataset viewer I get the following error,

TemplateSyntaxError: unexpected '|'
Traceback:
File "/usr/local/lib/python3.7/site-packages/streamlit/script_runner.py", line 338, in _run_script
    exec(code, module.__dict__)
File "/Users/sbmaruf/Documents/big-science/promptsource/promptsource/promptsource.py", line 294, in <module>
    prompt = template.apply(example, highlight_variables=True)
File "promptsource/templates.py", line 302, in apply
    rtemplate = env.from_string(jinja)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 941, in from_string
    return cls.from_code(self, self.compile(source), globals, None)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 638, in compile
    self.handle_exception(source=source_hint)
File "/usr/local/lib/python3.7/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
File "/usr/local/lib/python3.7/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
File "<unknown>", line 15, in template

@srush
Copy link
Collaborator

srush commented Jun 10, 2021

Oh wow, you have the hardest one. We'll try to help out.

\n}) %}\nGenerate named entities from the following sentence. \n{{\"\"}}\n{%\
\ for i in tokens -%}\n {{- \" \" if not loop.last else \"\" -}}\n {{\
\ i }}\n{% endfor %} \n|||\n{% set flag = 0 %}\n{% set outer_cnt = namespace(value=0)\
\ -%}\n{% for tok in tokens -%}\n {% set inner_cnt = namespace(value=0) -%}\n\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very complex. If there a reason you can't use loop index?

https://stackoverflow.com/questions/1567291/get-loop-index-of-outer-loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

reference: Natural question
87bb05ff-f6bf-4c0d-bbcc-56f75095f4a1: !Template
id: 87bb05ff-f6bf-4c0d-bbcc-56f75095f4a1
jinja: "{% set _chunk_lable_dict = ({\n0:\"O\",\n1:\"B-ADJP\",\n2:\"I-ADJP\",\n\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lable - > label

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sbmaruf
Copy link
Contributor Author

sbmaruf commented Jun 11, 2021

@srush

As suggested, changes are in this commit, 6539b83

New Prompt: 3 additional prompt added for ner, pos and chunks by this commit dc8d60e . The prompts intends to solve the following issue,

  • It is not expected that user will always provide labels strictly from the dataset. They may provide a subset of labels.
  • When user provided a subsample of labels of ner, pos or chunk tags, the model should understand that ONLY the given lables should be used for classification instead of original labels in the dataset. In this way, inference will be more natural.

So I randomly select some labels with the template and use them to label the sample. If the label is not in the selected labels I put O tag for that token.

TODO:

  • Randomly shuffle the tags. Now the labels are always in the same order. We should shuffle the lables. But I cannot find shuffle filter in the app.

Issue:

  • Test failing because of unused variable. I cannot update a dictionary in jinja without set method. There is a workaround using do extension. But I cannot find do extension in the app.

For convenience, A template that selects label randomly looks like below. I think the test is not passing because of _dummy variable.

{% set _ner_label_dict = ({
0:"O",
1:"B-PER",
2:"I-PER",
3:"B-ORG",
4:"I-ORG",
5:"B-LOC",
6:"I-LOC",
7:"B-MISC",
8:"I-MISC"
}) %}
{% set _random_ner_label_dict = ({}) %}
{% for k,v in _ner_label_dict.items() -%}
    {% set _rand_num=range(0, 100) | random %}
    {% if _rand_num > 50 %}
        {% set _dummy = _random_ner_label_dict.update({k:v}) %}
    {% endif %}
{% endfor %}
Generate named entities from the following sentence. The named entities are
{% for k,v in _random_ner_label_dict.items() -%}
    {{ v }}
    {{- ", " if not loop.last else "" -}}
{% endfor %}
{{""}}
{% for i in tokens -%}
    {{- " " if not loop.last else "" -}}
    {{ i }}
{% endfor %}
|||
{%- for tok in tokens -%}
    {%- set outer_loop = loop -%}
    {%- for label in ner_tags -%}
         {%- if outer_loop.index == loop.index -%}
            {{- "" if outer_loop.first else " " -}}
            {%- if label in _random_ner_label_dict -%}
                {{tok}}:{{ _random_ner_label_dict[label] }}
            {%- else -%}
                {{tok}}:O
            {% endif %}
        {%- endif -%}
    {%- endfor -%}
{%- endfor -%}

Please also look into this issue before merge, #174

@sbmaruf
Copy link
Contributor Author

sbmaruf commented Jun 11, 2021

More details on random label selection by prompt

We always include "O" tag for ner, pos and chunk labels. "O" lable indicated it is "other" (uncategorized) label.

In case of parts-of-speech tags, there are few labels that are weird. For example see a prompt with all pos labels,

Generate parts of speech from the following sentence. The parts of speech tags are ", '', #, $, (, ), ,, ., :, ``, CC, CD, DT, EX, FW, IN, JJ, JJR, JJS, LS, MD, NN, NNP, NNPS, NNS, NN|SYM, PDT, POS, PRP, PRP$, RB, RBR, RBS, RP, SYM, TO, UH, VB, VBD, VBG, VBN, VBP, VBZ, WDT, WP, WP$, WRB

In my opinion, here first 9 labels should be normalized. However in the regular prompt I didn't change them. But in the random label selection prompt named as pos_flat_question_with_label I did the following normalization,

{% if k>=0 and k<= 9 %}
    {% set _dummy = _random_pos_label_dict.update({0:"O"}) %}
{% else %}
    {% set _dummy = _random_pos_label_dict.update({k:v}) %}
{% endif %}

This will convert the first 9 weird label as "O" tag. Note that, there is not "O" in dataset for pos labels.

sbmaruf and others added 18 commits June 13, 2021 03:46
* first commit

* respond to review

* rephrase scinario to more reaonsble words
Co-authored-by: Jason Fries <jfries@mini.local>
* Add choice filter

* Change random to choice in templates

* Fix test
* Prompts for esnli

* Update templates.yaml

Changed neutral to neither entail nor contradict
* prompts for `quoref`

* update templates according to the comments
* copying prompts to `winogrande` subsets

* update templates according to the comments
* Add workaround for error in template highlighting.

* Found that this bug can also raise a TypeError.
…l task. (#141)

* add task template field

* update docs

* update docs

* update
* Add templates for the MC-TACO dataset

* Fixes
* Add template for snips_built_in_intents

* add spaces in intent options; task template checkbox
* added opus_tedtalks translation templates

* Added 5 templates for the mwsc dataset

* tempotarily removed opus_tedtalks

* Temporarily removed opus_tedtalks

* Updated mwsc templates - replace for loops with joins since always 2 options

* Added templates for the qasc dataset

* added trims to options in qasc templates

* added templates for selqa

* modified variable declaration in template

* modified variable declaration in template

* modified variable declaration in template

* using choice instead of random filter

Co-authored-by: Rachel Bawden <rachel.bawden@inria.fr@users.noreply.github.com>
* templates for wiki_qa dataset

* fixed typos

* added squad v2 prompts

* added two more templates and modified existing templates with variety of prompting sentences

* factorized templates with conditionals
* Add MDD templates

* Remove task4_reddit templates

* Update mdd templates

* Fix typo

* Fix mdd templates

* Fix typo

* Fix qa_recs template

* Fix qa_recs template

* Fix qa_recs template

* Fix qa_recs template

* Fix qa_recs template

* Replace random with choice

* Remove choice_idx from recommend_movie_2

* Add choice_idx global

* Fix globals
* feat: climate fever prompt templates.

Signed-off-by: Matteo Manica <drugilsberg@gmail.com>

* feat: updating labels and adding more templates

- paired templates as suggested in the PR review.

- a template considering al evidence statements.

Signed-off-by: Matteo Manica <drugilsberg@gmail.com>

* feat: adding templates for ncbi_disease.

Signed-off-by: Matteo Manica <drugilsberg@gmail.com>

* fix: setting variable before loop.

Adding task template flag.

Signed-off-by: Matteo Manica <drugilsberg@gmail.com>

Co-authored-by: Matteo Manica <tte@zurich.ibm.com>
thomasw21 and others added 15 commits June 13, 2021 03:51
* Add neural_code_search_prompts

* Add social_i_qa prompts

* Improve template for more compact version + randomly select answer for classification task

* Update prompt social_i_qa3 to better ask for a index type answer, and migrate random to choice

* Check task template

* Maske task template false for question hallucination
* Templates for stsb_multi_mt_en

* Added rounding and protected value in the prompt

* Fixing issues and checking the box
* add: prompt for atmoic

* add common gen dataset template

* removed template for atomic

* add: template with choice and sentence to concept for common_gen

* indicated task template for common_gen
* Add templates for DuoRC

* Fix templates

* Add changes from review

* Add answerable_question back to ParaphraseRC

* Fix structure issues with templates

* Fix styling issues

* Add choice for duorc templates
* wiki split

* more templates and removed ' ''
* Add app reviews template

* Fix template

* Fix typo

* Fix app reviews templates

* Fix app_reviews template
* Prompts for quartz

* Update templates.yaml

All marked as task templates
* Add scientific papers templates

* Add changes from review

* Fix pubmed templates

* Fix scientific_papers templates

* Update scientific_papers templates
* Templates for spider

* Adding recommendations and checking the box

* Adding reverse prompts
* Prompts for art more natural punctuation

* Change sentence to statement

Yest that's more accurate
* added ansq

* removed bad template
* newspop template

* made prompts clearer and capitalized relevant words
@sbmaruf sbmaruf closed this Jun 12, 2021
@sbmaruf
Copy link
Contributor Author

sbmaruf commented Jun 12, 2021

Deleting pull request. Creating a new one with updated zip function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet