code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _ontonotes_subset(ontonotes_reader , file_path , domain_identifier ) : u""" Iterates over the Ontonotes 5.0 dataset using an optional domain identifier. If the domain identifier is present, on...
Iterates over the Ontonotes 5.0 dataset using an optional domain identifier. If the domain identifier is present, only examples which contain the domain identifier in the file path are yielded.
_ontonotes_subset
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/ontonotes_ner.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/ontonotes_ner.py
MIT
def text_to_instance(self, # type: ignore tokens , pos_tags = None, gold_tree = None) : u""" We take `pre-tokenized` input here, because we don't have a tokenizer in this class. Para...
We take `pre-tokenized` input here, because we don't have a tokenizer in this class. Parameters ---------- tokens : ``List[str]``, required. The tokens in a given sentence. pos_tags ``List[str]``, optional, (default = None). The POS tags for the words in...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
MIT
def _strip_functional_tags(self, tree ) : u""" Removes all functional tags from constituency labels in an NLTK tree. We also strip off anything after a =, - or | character, because these are functional tags which we don't want to use. This modification is done in-pla...
Removes all functional tags from constituency labels in an NLTK tree. We also strip off anything after a =, - or | character, because these are functional tags which we don't want to use. This modification is done in-place.
_strip_functional_tags
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
MIT
def _get_gold_spans(self, # pylint: disable=arguments-differ tree , index , typed_spans ) : u""" Recursively construct the gold spans from an nltk ``Tree``. Labels are the constituen...
Recursively construct the gold spans from an nltk ``Tree``. Labels are the constituents, and in the case of nested constituents with the same spans, labels are concatenated in parent-child order. For example, ``(S (NP (D the) (N man)))`` would have an ``S-NP`` label for the oute...
_get_gold_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/penn_tree_bank.py
MIT
def text_to_instance(self, # type: ignore tokens , verb_label , tags = None) : u""" We take `pre-tokenized` input here, along with a verb label. The verb label should be a one...
We take `pre-tokenized` input here, along with a verb label. The verb label should be a one-hot binary vector, the same length as the tokens, indicating the position of the verb to find arguments for.
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/semantic_role_labeling.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/semantic_role_labeling.py
MIT
def text_to_instance(self, tokens , sentiment = None) : # type: ignore u""" We take `pre-tokenized` input here, because we don't have a tokenizer in this class. Parameters ---------- tokens : ``List[str]``, required. The tokens in a given s...
We take `pre-tokenized` input here, because we don't have a tokenizer in this class. Parameters ---------- tokens : ``List[str]``, required. The tokens in a given sentence. sentiment ``str``, optional, (default = None). The sentiment for this sentence. ...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/stanford_sentiment_tree_bank.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/stanford_sentiment_tree_bank.py
MIT
def text_to_instance(self, # type: ignore words , upos_tags , dependencies = None) : # pylint: disable=arguments-differ u""" Parameters ---------- wor...
Parameters ---------- words : ``List[str]``, required. The words in the sentence to be encoded. upos_tags : ``List[str]``, required. The universal dependencies POS tags for each word. dependencies ``List[Tuple[str, int]]``, optional (default = None) ...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/universal_dependencies.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/universal_dependencies.py
MIT
def text_to_instance(self, # type: ignore question , table_lines , example_lisp_string = None, dpd_output = None, tokenized_question = None) ...
Reads text inputs and makes an instance. WikitableQuestions dataset provides tables as TSV files, which we use for training. Parameters ---------- question : ``str`` Input question table_lines : ``List[str]`` The table content itself, as a list o...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/wikitables.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/wikitables.py
MIT
def _parse_example_line(lisp_string ) : u""" Training data in WikitableQuestions comes with examples in the form of lisp strings in the format: (example (id <example-id>) (utterance <question>) (context (graph tables.TableKnowled...
Training data in WikitableQuestions comes with examples in the form of lisp strings in the format: (example (id <example-id>) (utterance <question>) (context (graph tables.TableKnowledgeGraph <table-filename>)) (targetValue (list (descr...
_parse_example_line
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/wikitables.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/wikitables.py
MIT
def canonicalize_clusters(clusters ) : u""" The CONLL 2012 data includes 2 annotatated spans which are identical, but have different ids. This checks all clusters for spans which are identical, and if it finds any, merges the clusters...
The CONLL 2012 data includes 2 annotatated spans which are identical, but have different ids. This checks all clusters for spans which are identical, and if it finds any, merges the clusters containing the identical spans.
canonicalize_clusters
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/conll.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/conll.py
MIT
def text_to_instance(self, # type: ignore sentences , gold_clusters = None) : # pylint: disable=arguments-differ u""" Parameters ---------- sentences : ``List[List...
Parameters ---------- sentences : ``List[List[str]]``, required. A list of lists representing the tokenised words and sentences in the document. gold_clusters : ``Optional[List[List[Tuple[int, int]]]]``, optional (default = None) A list of all clusters in the doc...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/conll.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/conll.py
MIT
def text_to_instance(self, # type: ignore sentence , gold_clusters = None) : # pylint: disable=arguments-differ u""" Parameters ---------- sentences : ``List[Token]``,...
Parameters ---------- sentences : ``List[Token]``, required. The already tokenised sentence to analyse. gold_clusters : ``Optional[List[List[Tuple[int, int]]]]``, optional (default = None) A list of all clusters in the sentence, represented as word spans. Each cl...
text_to_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/winobias.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/winobias.py
MIT
def dataset_path_iterator(file_path ) : u""" An iterator returning file_paths in a directory containing CONLL-formatted files. """ logger.info(u"Reading CONLL sentences from dataset files at: %s", file_path) for root, _, files in list(os.walk(file_path...
An iterator returning file_paths in a directory containing CONLL-formatted files.
dataset_path_iterator
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
MIT
def dataset_document_iterator(self, file_path ) : u""" An iterator over CONLL formatted files which yields documents, regardless of the number of document annotations in a particular file. This is useful for conll data which has been preprocessed, ...
An iterator over CONLL formatted files which yields documents, regardless of the number of document annotations in a particular file. This is useful for conll data which has been preprocessed, such as the preprocessing which takes place for the 2012 CONLL Coreference Resolution task. ...
dataset_document_iterator
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
MIT
def sentence_iterator(self, file_path ) : u""" An iterator over the sentences in an individual CONLL formatted file. """ for document in self.dataset_document_iterator(file_path): for sentence in document: yield sentence
An iterator over the sentences in an individual CONLL formatted file.
sentence_iterator
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
MIT
def _process_coref_span_annotations_for_word(label , word_index , clusters , coref_stacks ) ...
For a given coref label, add it to a currently open span(s), complete a span(s) or ignore it, if it is outside of all spans. This method mutates the clusters and coref_stacks dictionaries. Parameters ---------- label : ``str`` The coref label for this word. ...
_process_coref_span_annotations_for_word
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
MIT
def _process_span_annotations_for_word(annotations , span_labels , current_span_labels ) : u""" Given a sequence of different label types for a single word and the c...
Given a sequence of different label types for a single word and the current span label we are inside, compute the BIO tag for each label and append to a list. Parameters ---------- annotations: ``List[str]`` A list of labels to compute BIO tags for. span_lab...
_process_span_annotations_for_word
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/ontonotes.py
MIT
def enumerate_spans(sentence , offset = 0, max_span_width = None, min_span_width = 1, filter_function = None) : u""" Given a sentence, return all token spans ...
Given a sentence, return all token spans within the sentence. Spans are `inclusive`. Additionally, you can provide a maximum and minimum span width, which will be used to exclude spans outside of this range. Finally, you can provide a function mapping ``List[T] -> bool``, which will be applied to ...
enumerate_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
MIT
def bio_tags_to_spans(tag_sequence , classes_to_ignore = None) : u""" Given a sequence corresponding to BIO tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are also i...
Given a sequence corresponding to BIO tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are also included (i.e those which do not start with a "B-LABEL"), as otherwise it is possible to get a perfect precision score whilst still predi...
bio_tags_to_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
MIT
def iob1_tags_to_spans(tag_sequence , classes_to_ignore = None) : u""" Given a sequence corresponding to IOB1 tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are als...
Given a sequence corresponding to IOB1 tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are also included (i.e., those where "B-LABEL" is not preceded by "I-LABEL" or "B-LABEL"). Parameters ---------- tag_sequence : List...
iob1_tags_to_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
MIT
def bioul_tags_to_spans(tag_sequence , classes_to_ignore = None) : u""" Given a sequence corresponding to BIOUL tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are ...
Given a sequence corresponding to BIOUL tags, extracts spans. Spans are inclusive and can be of zero length, representing a single word span. Ill-formed spans are not allowed and will raise ``InvalidTagSequence``. This function works properly when the spans are unlabeled (i.e., your labels are simp...
bioul_tags_to_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
MIT
def to_bioul(tag_sequence , encoding = u"IOB1") : u""" Given a tag sequence encoded with IOB1 labels, recode to BIOUL. In the IOB1 scheme, I is a token inside a span, O is a token outside a span and B is the beginning of span immediately following another span of the same...
Given a tag sequence encoded with IOB1 labels, recode to BIOUL. In the IOB1 scheme, I is a token inside a span, O is a token outside a span and B is the beginning of span immediately following another span of the same type. In the BIO scheme, I is a token inside a span, O is a token outside a...
to_bioul
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/dataset_utils/span_utils.py
MIT
def pick_paragraphs(self, evidence_files , question = None, answer_texts = None) : u""" Given a list of evidence documents, return a list of paragraphs to use as training examples....
Given a list of evidence documents, return a list of paragraphs to use as training examples. Each paragraph returned will be made into one training example. To aid in picking the best paragraph, you can also optionally pass the question text or the answer strings. Note, though, that ...
pick_paragraphs
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/triviaqa.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/triviaqa.py
MIT
def normalize_text(text ) : u""" Performs a normalization that is very similar to that done by the normalization functions in SQuAD and TriviaQA. This involves splitting and rejoining the text, and could be a somewhat expensive operation. """ return u' '.join([token ...
Performs a normalization that is very similar to that done by the normalization functions in SQuAD and TriviaQA. This involves splitting and rejoining the text, and could be a somewhat expensive operation.
normalize_text
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
MIT
def char_span_to_token_span(token_offsets , character_span ) : u""" Converts a character span from a passage into the corresponding token span in the tokenized version of the passage. If you pass in a character...
Converts a character span from a passage into the corresponding token span in the tokenized version of the passage. If you pass in a character span that does not correspond to complete tokens in the tokenized version, we'll do our best, but the behavior is officially undefined. We return an error flag...
char_span_to_token_span
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
MIT
def find_valid_answer_spans(passage_tokens , answer_texts ) : u""" Finds a list of token spans in ``passage_tokens`` that match the given ``answer_texts``. This tries to find all spans that would evaluate to correct given the SQuAD a...
Finds a list of token spans in ``passage_tokens`` that match the given ``answer_texts``. This tries to find all spans that would evaluate to correct given the SQuAD and TriviaQA official evaluation scripts, which do some normalization of the input text. Note that this could return duplicate spans! T...
find_valid_answer_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
MIT
def make_reading_comprehension_instance(question_tokens , passage_tokens , token_indexers , passage_text , t...
Converts a question, a passage, and an optional answer (or answers) to an ``Instance`` for use in a reading comprehension model. Creates an ``Instance`` with at least these fields: ``question`` and ``passage``, both ``TextFields``; and ``metadata``, a ``MetadataField``. Additionally, if both ``answer...
make_reading_comprehension_instance
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/util.py
MIT
def as_tensor(self, padding_lengths , cuda_device = -1) : u""" Given a set of specified padding lengths, actually pad the data in this field and return a torch Tensor (or a more complex data structure) of the correct shape. We ...
Given a set of specified padding lengths, actually pad the data in this field and return a torch Tensor (or a more complex data structure) of the correct shape. We also take a couple of parameters that are important when constructing torch Tensors. Parameters ---------- ...
as_tensor
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/fields/field.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/fields/field.py
MIT
def get_padding_lengths(self) : u""" The ``TextField`` has a list of ``Tokens``, and each ``Token`` gets converted into arrays by (potentially) several ``TokenIndexers``. This method gets the max length (over tokens) associated with each of these arrays. """ ...
The ``TextField`` has a list of ``Tokens``, and each ``Token`` gets converted into arrays by (potentially) several ``TokenIndexers``. This method gets the max length (over tokens) associated with each of these arrays.
get_padding_lengths
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/fields/text_field.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/fields/text_field.py
MIT
def sort_by_padding(instances , sorting_keys , # pylint: disable=invalid-sequence-index vocab , padding_noise = 0.0) : u""" Sorts the instances by their padding lengths, using the...
Sorts the instances by their padding lengths, using the keys in ``sorting_keys`` (in the order in which they are provided). ``sorting_keys`` is a list of ``(field_name, padding_key)`` tuples.
sort_by_padding
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/bucket_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/bucket_iterator.py
MIT
def add_epoch_number(batch , epoch ) : u""" Add the epoch number to the batch instances as a MetadataField. """ for instance in batch.instances: instance.fields[u'epoch_num'] = MetadataField(epoch) return batch
Add the epoch number to the batch instances as a MetadataField.
add_epoch_number
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def __call__(self, instances , num_epochs = None, shuffle = True, cuda_device = -1) : u""" Returns a generator that yields batches over the given dataset for the given nu...
Returns a generator that yields batches over the given dataset for the given number of epochs. If ``num_epochs`` is not specified, it will yield batches forever. Parameters ---------- instances : ``Iterable[Instance]`` The instances in the dataset. IMPORTANT...
__call__
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def _take_instances(self, instances , max_instances = None) : u""" Take the next `max_instances` instances from the given dataset. If `max_instances` is `None`, then just take all instances fro...
Take the next `max_instances` instances from the given dataset. If `max_instances` is `None`, then just take all instances from the dataset. If `max_instances` is not `None`, each call resumes where the previous one left off, and when you get to the end of the dataset you start again fr...
_take_instances
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def _memory_sized_lists(self, instances ) : u""" Breaks the dataset into "memory-sized" lists of instances, which it yields up one at a time until it gets through a full epoch. For example, if the dataset is alrea...
Breaks the dataset into "memory-sized" lists of instances, which it yields up one at a time until it gets through a full epoch. For example, if the dataset is already an in-memory list, and each epoch represents one pass through the dataset, it just yields back the dataset. Whe...
_memory_sized_lists
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def _ensure_batch_is_sufficiently_small(self, batch_instances ) : u""" If self._maximum_samples_per_batch is specified, then split the batch into smaller sub-batches if it exceeds the maximum size. """ if self._maximum_samples_per_batch i...
If self._maximum_samples_per_batch is specified, then split the batch into smaller sub-batches if it exceeds the maximum size.
_ensure_batch_is_sufficiently_small
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def get_num_batches(self, instances ) : u""" Returns the number of batches that ``dataset`` will be split into; if you want to track progress through the batch with the generator produced by ``__call__``, this could be useful. """ if is_lazy(insta...
Returns the number of batches that ``dataset`` will be split into; if you want to track progress through the batch with the generator produced by ``__call__``, this could be useful.
get_num_batches
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/iterators/data_iterator.py
MIT
def split_words(self, sentence ) : u""" Splits a sentence into word tokens. We handle four kinds of things: words with punctuation that should be ignored as a special case (Mr. Mrs., etc.), contractions/genitives (isn't, don't, Matt's), and beginning and ending punctua...
Splits a sentence into word tokens. We handle four kinds of things: words with punctuation that should be ignored as a special case (Mr. Mrs., etc.), contractions/genitives (isn't, don't, Matt's), and beginning and ending punctuation ("antennagate", (parentheticals), and such.). ...
split_words
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/tokenizers/word_splitter.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/tokenizers/word_splitter.py
MIT
def tokens_to_indices(self, tokens , vocabulary , index_name ) : u""" Takes a list of tokens and converts them to one or more sets of indices. This could be just ...
Takes a list of tokens and converts them to one or more sets of indices. This could be just an ID for each token from the vocabulary. Or it could split each token into characters and return one ID per character. Or (for instance, in the case of byte-pair encoding) there might not be a c...
tokens_to_indices
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/token_indexers/token_indexer.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/token_indexers/token_indexer.py
MIT
def pad_token_sequence(self, tokens , desired_num_tokens , padding_lengths ) : u""" This method pads a list of tokens to ``desired_num_to...
This method pads a list of tokens to ``desired_num_tokens`` and returns a padded copy of the input tokens. If the input token list is longer than ``desired_num_tokens`` then it will be truncated. ``padding_lengths`` is used to provide supplemental padding parameters which are needed ...
pad_token_sequence
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/data/token_indexers/token_indexer.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/data/token_indexers/token_indexer.py
MIT
def archive_model(serialization_dir , weights = _DEFAULT_WEIGHTS, files_to_archive = None) : u""" Archive the model weights, its training configuration, and its vocabulary to `model.tar.gz`. Include the additional ``files_to_archive`` i...
Archive the model weights, its training configuration, and its vocabulary to `model.tar.gz`. Include the additional ``files_to_archive`` if provided. Parameters ---------- serialization_dir: ``str`` The directory where the weights and vocabulary are written out. weights: ``str``, o...
archive_model
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/archival.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/archival.py
MIT
def load_archive(archive_file , cuda_device = -1, overrides = u"", weights_file = None) : u""" Instantiates an Archive from an archived `tar.gz` file. Parameters ---------- archive_file: ``str`` The archive file...
Instantiates an Archive from an archived `tar.gz` file. Parameters ---------- archive_file: ``str`` The archive file to load the model from. weights_file: ``str``, optional (default = None) The weights file to use. If unspecified, weights.th in the archive_file will be used. c...
load_archive
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/archival.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/archival.py
MIT
def forward(self, # type: ignore words , pos_tags , metadata , head_tags = None, head_indices = None) : ...
Parameters ---------- words : Dict[str, torch.LongTensor], required The output of ``TextField.as_array()``, which should typically be passed directly to a ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer`` tensors. At its mos...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def _construct_loss(self, head_tag_representation , child_tag_representation , attended_arcs , head_indices , head_tags , ...
Computes the arc and tag loss for a sequence given gold head indices and tags. Parameters ---------- head_tag_representation : ``torch.Tensor``, required. A tensor of shape (batch_size, sequence_length, tag_representation_dim), which will be used to generate pre...
_construct_loss
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def _greedy_decode(self, head_tag_representation , child_tag_representation , attended_arcs , mask ) : u""" Decodes the head...
Decodes the head and head tag predictions by decoding the unlabeled arcs independently for each word and then again, predicting the head tags of these greedily chosen arcs indpendently. Note that this method of decoding is not guaranteed to produce trees (i.e. there maybe be multiple ro...
_greedy_decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def _mst_decode(self, head_tag_representation , child_tag_representation , attended_arcs , mask ) : u""" Decodes the head and head tag p...
Decodes the head and head tag predictions using the Edmonds' Algorithm for finding minimum spanning trees on directed graphs. Nodes in the graph are the words in the sentence, and between each pair of nodes, there is an edge in each direction, where the weight of the edge corresponds ...
_mst_decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def _get_head_tags(self, head_tag_representation , child_tag_representation , head_indices ) : u""" Decodes the head tags given the head and child tag representations and a ...
Decodes the head tags given the head and child tag representations and a tensor of head indices to compute tags for. Note that these are either gold or predicted heads, depending on whether this function is being called to compute the loss, or if it's being called during inference. ...
_get_head_tags
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def _get_mask_for_eval(self, mask , pos_tags ) : u""" Dependency evaluation excludes words are punctuation. Here, we create a new mask to exclude word indices which have a "punctuat...
Dependency evaluation excludes words are punctuation. Here, we create a new mask to exclude word indices which have a "punctuation-like" part of speech tag. Parameters ---------- mask : ``torch.LongTensor``, required. The original mask. pos_tags : ``...
_get_mask_for_eval
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biaffine_dependency_parser.py
MIT
def forward(self, # type: ignore tokens , label = None) : # pylint: disable=arguments-differ u""" Parameters ---------- tokens : Dict[str, torch.LongTensor], required ...
Parameters ---------- tokens : Dict[str, torch.LongTensor], required The output of ``TextField.as_array()``. label : torch.LongTensor, optional (default = None) A variable representing the label for each instance in the batch. Returns ------- ...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biattentive_classification_network.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biattentive_classification_network.py
MIT
def decode(self, output_dict ) : u""" Does a simple argmax over the class probabilities, converts indices to string labels, and adds a ``"label"`` key to the dictionary with the result. """ predictions = output_dict[u"class_probab...
Does a simple argmax over the class probabilities, converts indices to string labels, and adds a ``"label"`` key to the dictionary with the result.
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/biattentive_classification_network.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/biattentive_classification_network.py
MIT
def forward(self, # type: ignore premise , hypothesis , label = None, metadata = None # pylint:disable=unused-argument ) ...
Parameters ---------- premise : Dict[str, torch.LongTensor] The premise from a ``TextField`` hypothesis : Dict[str, torch.LongTensor] The hypothesis from a ``TextField`` label : torch.LongTensor, optional (default = None) The label for the pa...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/bimpm.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/bimpm.py
MIT
def forward(self, # type: ignore tokens , spans , metadata , pos_tags = None, span_labels = None) : ...
Parameters ---------- tokens : Dict[str, torch.LongTensor], required The output of ``TextField.as_array()``, which should typically be passed directly to a ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer`` tensors. At its mo...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/constituency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/constituency_parser.py
MIT
def decode(self, output_dict ) : u""" Constructs an NLTK ``Tree`` given the scored spans. We also switch to exclusive span ends when constructing the tree representation, because it makes indexing into lists cleaner for ranges of text, ra...
Constructs an NLTK ``Tree`` given the scored spans. We also switch to exclusive span ends when constructing the tree representation, because it makes indexing into lists cleaner for ranges of text, rather than individual indices. Finally, for batch prediction, we will have padded spans...
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/constituency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/constituency_parser.py
MIT
def construct_trees(self, predictions , all_spans , num_spans , sentences , pos_tags = None) : ...
Construct ``nltk.Tree``'s for each batch element by greedily nesting spans. The trees use exclusive end indices, which contrasts with how spans are represented in the rest of the model. Parameters ---------- predictions : ``torch.FloatTensor``, required. A t...
construct_trees
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/constituency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/constituency_parser.py
MIT
def resolve_overlap_conflicts_greedily(spans ) : u""" Given a set of spans, removes spans which overlap by evaluating the difference in probability between one being labeled and the other explicitly having no label and vice-versa. The worst c...
Given a set of spans, removes spans which overlap by evaluating the difference in probability between one being labeled and the other explicitly having no label and vice-versa. The worst case time complexity of this method is ``O(k * n^4)`` where ``n`` is the length of the sentence that...
resolve_overlap_conflicts_greedily
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/constituency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/constituency_parser.py
MIT
def construct_tree_from_spans(spans_to_labels , sentence , pos_tags = None) : u""" Parameters ---------- spans_to_labels : ``Dict[Tuple[int, int], str]``, required. ...
Parameters ---------- spans_to_labels : ``Dict[Tuple[int, int], str]``, required. A mapping from spans to constituency labels. sentence : ``List[str]``, required. A list of tokens forming the sentence to be parsed. pos_tags : ``List[str]``, optional (defa...
construct_tree_from_spans
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/constituency_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/constituency_parser.py
MIT
def forward(self, # type: ignore tokens , tags = None, metadata = None) : # pylint: disable=arguments-differ u""" Parameters ---------- t...
Parameters ---------- tokens : ``Dict[str, torch.LongTensor]``, required The output of ``TextField.as_array()``, which should typically be passed directly to a ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer`` tensors. At it...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/crf_tagger.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/crf_tagger.py
MIT
def decode(self, output_dict ) : u""" Converts the tag ids to the actual tags. ``output_dict["tags"]`` is a list of lists of tag_ids, so we use an ugly nested list comprehension. """ output_dict[u"tags"] = [ ...
Converts the tag ids to the actual tags. ``output_dict["tags"]`` is a list of lists of tag_ids, so we use an ugly nested list comprehension.
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/crf_tagger.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/crf_tagger.py
MIT
def forward(self, # type: ignore premise , hypothesis , label = None, metadata = None) : # pylint: disable=arguments-differ ...
Parameters ---------- premise : Dict[str, torch.LongTensor] From a ``TextField`` hypothesis : Dict[str, torch.LongTensor] From a ``TextField`` label : torch.IntTensor, optional, (default = None) From a ``LabelField`` metadata : ``List[...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/decomposable_attention.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/decomposable_attention.py
MIT
def _load(cls, config , serialization_dir , weights_file = None, cuda_device = -1) : u""" Ensembles don't have vocabularies or weights of their own, so they override _load. """ model_params = config.ge...
Ensembles don't have vocabularies or weights of their own, so they override _load.
_load
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/ensemble.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/ensemble.py
MIT
def forward(self, # type: ignore premise , hypothesis , label = None, metadata = None # pylint:disable=unused-argument ) ...
Parameters ---------- premise : Dict[str, torch.LongTensor] From a ``TextField`` hypothesis : Dict[str, torch.LongTensor] From a ``TextField`` label : torch.IntTensor, optional (default = None) From a ``LabelField`` metadata : ``List[D...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/esim.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/esim.py
MIT
def get_regularization_penalty(self) : u""" Computes the regularization penalty for the model. Returns 0 if the model was not configured to use regularization. """ if self._regularizer is None: return 0.0 else: return s...
Computes the regularization penalty for the model. Returns 0 if the model was not configured to use regularization.
get_regularization_penalty
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def get_parameters_for_histogram_tensorboard_logging( # pylint: disable=invalid-name self) : u""" Returns the name of model parameters used for logging histograms to tensorboard. """ return [name for name, _ in self.named_parameters()]
Returns the name of model parameters used for logging histograms to tensorboard.
get_parameters_for_histogram_tensorboard_logging
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def forward_on_instances(self, instances ) : u""" Takes a list of :class:`~allennlp.data.instance.Instance`s, converts that text into arrays using this model's :class:`Vocabulary`, passes those arrays through :...
Takes a list of :class:`~allennlp.data.instance.Instance`s, converts that text into arrays using this model's :class:`Vocabulary`, passes those arrays through :func:`self.forward()` and :func:`self.decode()` (which by default does nothing) and returns the result. Before returning the ...
forward_on_instances
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def _get_prediction_device(self) : u""" This method checks the device of the model parameters to determine the cuda_device this model should be run on for predictions. If there are no parameters, it returns -1. Returns ------- The cuda device this model should run...
This method checks the device of the model parameters to determine the cuda_device this model should be run on for predictions. If there are no parameters, it returns -1. Returns ------- The cuda device this model should run on for predictions.
_get_prediction_device
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def _maybe_warn_for_unseparable_batches(self, output_key ): u""" This method warns once if a user implements a model which returns a dictionary with values which we are unable to split back up into elements of the batch. This is controlled by a class attribute ``_warn_for_unseperable...
This method warns once if a user implements a model which returns a dictionary with values which we are unable to split back up into elements of the batch. This is controlled by a class attribute ``_warn_for_unseperable_batches`` because it would be extremely verbose otherwise.
_maybe_warn_for_unseparable_batches
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def _load(cls, config , serialization_dir , weights_file = None, cuda_device = -1) : u""" Instantiates an already-trained model, based on the experiment configuration and some optional overrides. """ ...
Instantiates an already-trained model, based on the experiment configuration and some optional overrides.
_load
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def load(cls, config , serialization_dir , weights_file = None, cuda_device = -1) : u""" Instantiates an already-trained model, based on the experiment configuration and some optional overrides. Parameter...
Instantiates an already-trained model, based on the experiment configuration and some optional overrides. Parameters ---------- config: Params The configuration that was used to train the model. It should definitely have a `model` section, and should pro...
load
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/model.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/model.py
MIT
def forward(self, # type: ignore tokens , verb_indicator , tags = None, metadata = None) : # pylint: disable=arguments-differ u"...
Parameters ---------- tokens : Dict[str, torch.LongTensor], required The output of ``TextField.as_array()``, which should typically be passed directly to a ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer`` tensors. At its mo...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
MIT
def decode(self, output_dict ) : u""" Does constrained viterbi decoding on class probabilities output in :func:`forward`. The constraint simply specifies that the output tags must be a valid BIO sequence. We add a ``"tags"`` key to the ...
Does constrained viterbi decoding on class probabilities output in :func:`forward`. The constraint simply specifies that the output tags must be a valid BIO sequence. We add a ``"tags"`` key to the dictionary with the result.
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
MIT
def get_viterbi_pairwise_potentials(self): u""" Generate a matrix of pairwise transition potentials for the BIO labels. The only constraint implemented here is that I-XXX labels must be preceded by either an identical I-XXX tag or a B-XXX tag. In order to achieve this constraint,...
Generate a matrix of pairwise transition potentials for the BIO labels. The only constraint implemented here is that I-XXX labels must be preceded by either an identical I-XXX tag or a B-XXX tag. In order to achieve this constraint, pairs of labels which do not satisfy this constraint h...
get_viterbi_pairwise_potentials
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
MIT
def write_to_conll_eval_file(prediction_file , gold_file , verb_index , sentence , prediction , gold_labels ): u"...
Prints predicate argument predictions and gold labels for a single verbal predicate in a sentence to two provided file references. Parameters ---------- prediction_file : TextIO, required. A file reference to print predictions to. gold_file : TextIO, required. A file reference ...
write_to_conll_eval_file
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
MIT
def convert_bio_tags_to_conll_format(labels ): u""" Converts BIO formatted SRL tags to the format required for evaluation with the official CONLL 2005 perl script. Spans are represented by bracketed labels, with the labels of words inside spans being the same as those outside spans. Beginn...
Converts BIO formatted SRL tags to the format required for evaluation with the official CONLL 2005 perl script. Spans are represented by bracketed labels, with the labels of words inside spans being the same as those outside spans. Beginning spans always have a opening bracket and a closing asterisk (e...
convert_bio_tags_to_conll_format
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_role_labeler.py
MIT
def forward(self, # type: ignore tokens , tags = None, metadata = None) : # pylint: disable=arguments-differ u""" Parameters ---------- t...
Parameters ---------- tokens : Dict[str, torch.LongTensor], required The output of ``TextField.as_array()``, which should typically be passed directly to a ``TextFieldEmbedder``. This output is a dictionary mapping keys to ``TokenIndexer`` tensors. At its mo...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/simple_tagger.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/simple_tagger.py
MIT
def decode(self, output_dict ) : u""" Does a simple position-wise argmax over each token, converts indices to string labels, and adds a ``"tags"`` key to the dictionary with the result. """ all_predictions = output_dict[u'class_pr...
Does a simple position-wise argmax over each token, converts indices to string labels, and adds a ``"tags"`` key to the dictionary with the result.
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/simple_tagger.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/simple_tagger.py
MIT
def forward(self, # type: ignore text , spans , span_labels = None, metadata = None) : # pylint: disable=arguments-differ u""" ...
Parameters ---------- text : ``Dict[str, torch.LongTensor]``, required. The output of a ``TextField`` representing the text of the document. spans : ``torch.IntTensor``, required. A tensor of shape (batch_size, num_spans, 2), representing the inclusiv...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def decode(self, output_dict ): u""" Converts the list of spans and predicted antecedent indices into clusters of spans for each element in the batch. Parameters ---------- output_dict : ``Dict[str, torch.Tensor]``, required. The resul...
Converts the list of spans and predicted antecedent indices into clusters of spans for each element in the batch. Parameters ---------- output_dict : ``Dict[str, torch.Tensor]``, required. The result of calling :func:`forward` on an instance or batch of instances. ...
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def _generate_valid_antecedents(num_spans_to_keep , max_antecedents , device ): ...
This method generates possible antecedents per span which survived the pruning stage. This procedure is `generic across the batch`. The reason this is the case is that each span in a batch can be coreferent with any previous span, but here we are computing the possible `indices` of thes...
_generate_valid_antecedents
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def _compute_span_pair_embeddings(self, top_span_embeddings , antecedent_embeddings , antecedent_offsets ): u""" Computes an embedding r...
Computes an embedding representation of pairs of spans for the pairwise scoring function to consider. This includes both the original span representations, the element-wise similarity of the span representations, and an embedding representation of the distance between the two spans. ...
_compute_span_pair_embeddings
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def _compute_antecedent_gold_labels(top_span_labels , antecedent_labels ): u""" Generates a binary indicator for every pair of spans. This label is one if and only if the pair of spans belong to the same cluster. The labels ...
Generates a binary indicator for every pair of spans. This label is one if and only if the pair of spans belong to the same cluster. The labels are augmented with a dummy antecedent at the zeroth position, which represents the prediction that a span does not have any antecedent. ...
_compute_antecedent_gold_labels
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def _compute_coreference_scores(self, pairwise_embeddings , top_span_mention_scores , antecedent_mention_scores , antecede...
Computes scores for every pair of spans. Additionally, a dummy label is included, representing the decision that the span is not coreferent with anything. For the dummy label, the score is always zero. For the true antecedent spans, the score consists of the pairwise antecedent score an...
_compute_coreference_scores
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/coreference_resolution/coref.py
MIT
def forward(self, # type: ignore source_tokens , target_tokens = None) : # pylint: disable=arguments-differ u""" Decoder logic for producing the entire target sequence. Pa...
Decoder logic for producing the entire target sequence. Parameters ---------- source_tokens : Dict[str, torch.LongTensor] The output of ``TextField.as_array()`` applied on the source ``TextField``. This will be passed through a ``TextFieldEmbedder`` and then throu...
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
MIT
def _prepare_decode_step_input(self, input_indices , decoder_hidden_state = None, encoder_outputs = None, encoder_outputs_mask ...
Given the input indices for the current timestep of the decoder, and all the encoder outputs, compute the input at the current timestep. Note: This method is agnostic to whether the indices are gold indices or the predictions made by the decoder at the last timestep. So, this can be us...
_prepare_decode_step_input
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
MIT
def _get_loss(logits , targets , target_mask ) : u""" Takes logits (unnormalized outputs from the decoder) of size (batch_size, num_decoding_steps, num_classes), target indices of size (batc...
Takes logits (unnormalized outputs from the decoder) of size (batch_size, num_decoding_steps, num_classes), target indices of size (batch_size, num_decoding_steps+1) and corresponding masks of size (batch_size, num_decoding_steps+1) steps and computes cross entropy loss while taking the...
_get_loss
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
MIT
def decode(self, output_dict ) : u""" This method overrides ``Model.decode``, which gets called after ``Model.forward``, at test time, to finalize predictions. The logic for the decoder part of the encoder-decoder lives within the ``forwa...
This method overrides ``Model.decode``, which gets called after ``Model.forward``, at test time, to finalize predictions. The logic for the decoder part of the encoder-decoder lives within the ``forward`` method. This method trims the output predictions to the first end symbol, replace...
decode
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/encoder_decoders/simple_seq2seq.py
MIT
def ensemble(subresults ) : u""" Identifies the best prediction given the results from the submodels. Parameters ---------- index : int The index within this index to ensemble subresults : List[Dict[str, torch.Tensor]] Returns -----...
Identifies the best prediction given the results from the submodels. Parameters ---------- index : int The index within this index to ensemble subresults : List[Dict[str, torch.Tensor]] Returns ------- The index of the best submodel.
ensemble
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/reading_comprehension/bidaf_ensemble.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/reading_comprehension/bidaf_ensemble.py
MIT
def forward(self, # type: ignore sentence , worlds , actions , agenda , identifier = None, labels ...
Decoder logic for producing type constrained target sequences that maximize coverage of their respective agendas, and minimize a denotation based loss.
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
MIT
def _get_checklist_info(self, agenda , all_actions ): ...
Takes an agenda and a list of all actions and returns a target checklist against which the checklist at each state will be compared to compute a loss, indices of ``terminal_actions``, and a ``checklist_mask`` that indicates which of the terminal actions are relevant for checklist loss c...
_get_checklist_info
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
MIT
def _get_state_cost(self, state ) : u""" Return the costs a finished state. Since it is a finished state, the group size will be 1, and hence we'll return just one cost. """ if not state.is_finished(): raise RuntimeError(u"_get_state_co...
Return the costs a finished state. Since it is a finished state, the group size will be 1, and hence we'll return just one cost.
_get_state_cost
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
MIT
def _get_state_info(self, state) : u""" This method is here for debugging purposes, in case you want to look at the what the model is learning. It may be inefficient to call it while training the model on real data. """ if len(state.batch_indices) == 1 and state...
This method is here for debugging purposes, in case you want to look at the what the model is learning. It may be inefficient to call it while training the model on real data.
_get_state_info
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_coverage_semantic_parser.py
MIT
def is_finished(self) : u"""This method is identical to ``WikiTablesDecoderState.is_finished``.""" if len(self.batch_indices) != 1: raise RuntimeError(u"is_finished() is only defined with a group_size of 1") return self.grammar_state[0].is_finished()
This method is identical to ``WikiTablesDecoderState.is_finished``.
is_finished
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_state.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_state.py
MIT
def take_step(self, # type: ignore state , max_actions = None, allowed_actions = None) : u""" Given a ``NlvrDecoderState``, returns a list of next states that are sorted by their scores....
Given a ``NlvrDecoderState``, returns a list of next states that are sorted by their scores. This method is very similar to ``WikiTablesDecoderStep._take_step``. The differences are that depending on the type of supervision being used, we may not have a notion of "allowed actions" here,...
take_step
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def _get_predicted_embedding_addition(state ) : u""" Computes checklist balance, uses it to get the embeddings of desired terminal actions yet to be produced by the decoder, and returns their sum for the decoder to add it to the predicted embedding to bias...
Computes checklist balance, uses it to get the embeddings of desired terminal actions yet to be produced by the decoder, and returns their sum for the decoder to add it to the predicted embedding to bias the prediction towards missing actions.
_get_predicted_embedding_addition
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def _get_next_state_info_with_agenda( state , considered_actions , action_logits , action_mask ): ...
We return a list of log probabilities and checklist states corresponding to next actions that are not padding. This method is applicable to the case where we do not have target action sequences and are relying on agendas for training.
_get_next_state_info_with_agenda
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def _get_next_state_info_without_agenda(state , considered_actions , action_logits , action_mask ): ...
We return a list of log probabilities corresponding to actions that are not padding. This method is related to the training scenario where we have target action sequences for training.
_get_next_state_info_without_agenda
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def attend_on_sentence(self, query , encoder_outputs , encoder_output_mask ) : u""" This method is almost identical to ``WikiTablesDecoderStep.atten...
This method is almost identical to ``WikiTablesDecoderStep.attend_on_question``. We just don't return the attention weights. Given a query (which is typically the decoder hidden state), compute an attention over the output of the sentence encoder, and return a weighted sum of the senten...
attend_on_sentence
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def _get_action_embeddings(state , actions_to_embed ) : u""" This method is identical to ``WikiTablesDecoderStep._get_action_embeddings`` Returns an embedded representation for all actions in ``ac...
This method is identical to ``WikiTablesDecoderStep._get_action_embeddings`` Returns an embedded representation for all actions in ``actions_to_embed``, using the state in ``NlvrDecoderState``. Parameters ---------- state : ``NlvrDecoderState`` The current s...
_get_action_embeddings
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def _compute_new_states(cls, state , action_logprobs , hidden_state , memory_cell , action_embedding...
This method is very similar to ``WikiTabledDecoderStep._compute_new_states``. The difference here is that we also keep track of checklists if they are passed to this method.
_compute_new_states
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_decoder_step.py
MIT
def forward(self, # type: ignore sentence , worlds , actions , identifier = None, target_action_sequences = None, ...
Decoder logic for producing type constrained target sequences, trained to maximize marginal likelihod over a set of approximate logical forms.
forward
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_direct_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_direct_semantic_parser.py
MIT
def _get_action_strings(cls, possible_actions , action_indices ) : u""" Takes a list of possible actions and indices of decoded actions into those possible actions ...
Takes a list of possible actions and indices of decoded actions into those possible actions for a batch and returns sequences of action strings. We assume ``action_indices`` is a dict mapping batch indices to k-best decoded sequence lists.
_get_action_strings
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_semantic_parser.py
MIT
def _embed_actions(self, actions ): u""" Given all of the possible actions for all batch instances, produce an embedding for them. Th...
Given all of the possible actions for all batch instances, produce an embedding for them. There will be significant overlap in this list, as the production rules from the grammar are shared across all batch instances. Our returned tensor has an embedding for each `unique` action, so we...
_embed_actions
python
plasticityai/magnitude
pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_semantic_parser.py
https://github.com/plasticityai/magnitude/blob/master/pymagnitude/third_party/allennlp/models/semantic_parsing/nlvr/nlvr_semantic_parser.py
MIT