예제 #1
0
 def config_spec(self) -> types.Spec:
     return {
         INTERPOLATION_KEY:
         types.Scalar(min_val=5, max_val=200, default=IG_STEPS, step=1),
         MAX_DIST_KEY:
         types.Scalar(min_val=0.0, max_val=1.0, default=0.1, step=0.02)
     }
예제 #2
0
 def spec(self):
   return {
       'span1_embs': lit_types.Embeddings(),
       'span2_embs': lit_types.Embeddings(),
       'label': lit_types.Scalar(),
       'src_idx': lit_types.Scalar(),
       'edge_idx': lit_types.Scalar(),
   }
예제 #3
0
 def input_spec(self):
     return {
         'body_mass_g': lit_types.Scalar(),
         'culmen_depth_mm': lit_types.Scalar(),
         'culmen_length_mm': lit_types.Scalar(),
         'flipper_length_mm': lit_types.Scalar(),
         'island': lit_types.CategoryLabel(vocab=VOCABS['island']),
         'sex': lit_types.CategoryLabel(vocab=VOCABS['sex']),
     }
예제 #4
0
def set_up_pandas_dataframe_and_columns():
    dataframe = pd.DataFrame.from_dict({
        "feature_1": [1.0],
        "feature_2": [3.0],
        "label": [1.0]
    })
    columns = collections.OrderedDict([
        ("feature_1", lit_types.Scalar()),
        ("feature_2", lit_types.Scalar()),
        ("label", lit_types.RegressionScore()),
    ])
    yield dataframe, columns
예제 #5
0
파일: winogender.py 프로젝트: zhiyiZeng/lit
 def spec(self):
     return {
         "text":
         lit_types.TextSegment(),
         "tokens":
         lit_types.Tokens(parent="text"),
         "coref":
         lit_types.EdgeLabels(align="tokens"),
         # Metadata fields for filtering and analysis.
         "occupation":
         lit_types.CategoryLabel(),
         "participant":
         lit_types.CategoryLabel(),
         "answer":
         lit_types.CategoryLabel(vocab=ANSWER_VOCAB),
         "someone":
         lit_types.CategoryLabel(vocab=["True", "False"]),
         "pronouns":
         lit_types.CategoryLabel(vocab=list(PRONOUNS_BY_GENDER.values())),
         "pronoun_type":
         lit_types.CategoryLabel(vocab=["NOM", "POSS", "ACC"]),
         "gender":
         lit_types.CategoryLabel(vocab=[g.name for g in Gender]),
         "pf_bls":
         lit_types.Scalar(),
     }
예제 #6
0
 def test_find_spec_keys(self):
   spec = {
       "score": types.RegressionScore(),
       "scalar_foo": types.Scalar(),
       "text": types.TextSegment(),
       "emb_0": types.Embeddings(),
       "emb_1": types.Embeddings(),
       "tokens": types.Tokens(),
       "generated_text": types.GeneratedText(),
   }
   self.assertEqual(["score"], utils.find_spec_keys(spec,
                                                    types.RegressionScore))
   self.assertEqual(["text", "tokens", "generated_text"],
                    utils.find_spec_keys(spec,
                                         (types.TextSegment, types.Tokens)))
   self.assertEqual(["emb_0", "emb_1"],
                    utils.find_spec_keys(spec, types.Embeddings))
   self.assertEqual([], utils.find_spec_keys(spec, types.AttentionHeads))
   # Check subclasses
   self.assertEqual(
       list(spec.keys()), utils.find_spec_keys(spec, types.LitType))
   self.assertEqual(["text", "generated_text"],
                    utils.find_spec_keys(spec, types.TextSegment))
   self.assertEqual(["score", "scalar_foo"],
                    utils.find_spec_keys(spec, types.Scalar))
예제 #7
0
 def config_spec(self) -> types.Spec:
     return {
         SALIENCE_MAPPER_KEY:
         types.CategoryLabel(required=True,
                             vocab=list(self.salience_mappers.keys())),
         N_CLUSTERS_KEY:
         types.Scalar(min_val=2, max_val=100, default=2, step=1),
     }
예제 #8
0
 def input_spec(self) -> lit_types.Spec:
     return {
         'size':
         lit_types.CategoryLabel(vocab=['small', 'medium', 'large']),
         'weight': lit_types.Scalar(),
         'legs': lit_types.Boolean(),
         'description': lit_types.String(),
     }
예제 #9
0
 def config_spec(self) -> types.Spec:
     return {
         CLASS_KEY:
         types.TextSegment(default=''),
         NORMALIZATION_KEY:
         types.Boolean(default=True),
         INTERPOLATION_KEY:
         types.Scalar(min_val=5, max_val=100, default=30, step=1)
     }
 def config_spec(self) -> lit_types.Spec:
     return {
         NUM_EXAMPLES_KEY:
         lit_types.Scalar(min_val=1,
                          max_val=20,
                          default=NUM_EXAMPLES_DEFAULT,
                          step=1),
         MAX_FLIPS_KEY:
         lit_types.Scalar(min_val=1,
                          max_val=10,
                          default=MAX_FLIPS_DEFAULT,
                          step=1),
         PREDICTION_KEY:
         lit_types.FieldMatcher(
             spec='output', types=['MulticlassPreds', 'RegressionScore']),
         REGRESSION_THRESH_KEY:
         lit_types.TextSegment(default=str(REGRESSION_THRESH_DEFAULT)),
     }
예제 #11
0
파일: analyze.py 프로젝트: sillsdev/silnlp
 def output_spec(self) -> lit_types.Spec:
     return {
         "src_tokens":
         lit_types.Tokens(parent="src_text"),
         "trg_text":
         lit_types.GeneratedText(parent="ref_text"),
         "trg_tokens":
         lit_types.Tokens(parent="trg_text"),
         "attention":
         lit_types.AttentionHeads(align_in="src_tokens",
                                  align_out="trg_tokens"),
         "pred_tokens":
         lit_types.TokenTopKPreds(align="trg_tokens", parent="trg_text"),
         "encoder_final_embedding":
         lit_types.Embeddings(),
         "ter":
         lit_types.Scalar(),
         "chrf3":
         lit_types.Scalar(),
     }
예제 #12
0
 def input_spec(self):
     return {
         'text':
         lit_types.TextSegment(),
         'tokens':
         lit_types.Tokens(parent='text'),
         'coref':
         lit_types.EdgeLabels(align='tokens'),
         # Index of predicted (single) edge for Winogender
         'answer':
         lit_types.CategoryLabel(vocab=winogender.ANSWER_VOCAB,
                                 required=False),
         # TODO(b/172975096): allow plotting of scalars from input data,
         # so we don't need to add this to the predictions.
         'pf_bls':
         lit_types.Scalar(required=False),
     }
예제 #13
0
 def output_spec(self):
     # TODO(lit-dev): also return the embeddings for each span on datasets
     # with a fixed number of targets; for Winogender this would be
     # {occupation, other participant, pronoun}
     return {
         'tokens':
         lit_types.Tokens(parent='text'),
         'coref':
         lit_types.EdgeLabels(align='tokens'),
         'pred_answer':
         lit_types.MulticlassPreds(vocab=winogender.ANSWER_VOCAB,
                                   parent='answer'),
         # TODO(b/172975096): allow plotting of scalars from input data,
         # so we don't need to add this to the predictions.
         'pf_bls':
         lit_types.Scalar(),
     }
예제 #14
0
 def testTfxModel(self):
     input_spec = {'input_0': lit_types.Scalar()}
     output_spec = {
         'output_0':
         lit_types.MulticlassPreds(vocab=['0', '1'], parent='input_0')
     }
     config = tfx_model.TFXModelConfig(self._path, input_spec, output_spec)
     lit_model = tfx_model.TFXModel(config)
     result = list(lit_model.predict([{'input_0': 0.5}]))
     self.assertLen(result, 1)
     result = result[0]
     self.assertListEqual(list(result.keys()), ['output_0'])
     self.assertLen(result['output_0'], 2)
     self.assertIsInstance(result['output_0'][0], float)
     self.assertIsInstance(result['output_0'][1], float)
     self.assertDictEqual(lit_model.input_spec(), input_spec)
     self.assertDictEqual(lit_model.output_spec(), output_spec)
예제 #15
0
파일: t5.py 프로젝트: smesaric/lit
 def output_spec(self):
   spec = {
       "input_tokens": lit_types.Tokens(parent="input_text"),
       "generation": lit_types.GeneratedText(parent="target_text"),
       "encoder_final_embedding": lit_types.Embeddings(),
       # If target text is given, the following will also be populated.
       "target_tokens": lit_types.Tokens(parent="target_text"),
       "pred_tokens": lit_types.TokenTopKPreds(align="target_tokens"),
       "rougeL": lit_types.Scalar(),
   }
   if self.config.output_attention:
     # Add attention for each layer.
     for i in range(self.num_layers):
       spec[f"encoder_layer_{i:d}_attention"] = lit_types.AttentionHeads(
           align=("input_tokens", "input_tokens"))
       spec[f"decoder_layer_{i:d}_attention"] = lit_types.AttentionHeads(
           align=("target_tokens", "target_tokens"))
   return spec
예제 #16
0
 def test_remap(self):
     """Test remap method."""
     spec = {
         "score": types.Scalar(),
         "text": types.TextSegment(),
     }
     datapoints = [
         {
             "score": 0,
             "text": "a"
         },
         {
             "score": 0,
             "text": "b"
         },
     ]
     dset = lit_dataset.Dataset(spec, datapoints)
     remap_dict = {"score": "val", "nothing": "nada"}
     remapped_dset = dset.remap(remap_dict)
     self.assertIn("val", remapped_dset.spec())
     self.assertNotIn("score", remapped_dset.spec())
     self.assertEqual({"val": 0, "text": "a"}, remapped_dset.examples[0])
예제 #17
0
 def input_spec(self):
     return {'val': lit_types.Scalar()}
예제 #18
0
 def input_spec(self):
   return {
       'span1_embs': lit_types.Embeddings(),
       'span2_embs': lit_types.Embeddings(),
       'label': lit_types.Scalar(required=False),  # in range [0,1]
   }
예제 #19
0
def feature_types():
    yield collections.OrderedDict([("feature_1", lit_types.Scalar()),
                                   ("feature_2", lit_types.Scalar())])
예제 #20
0
 def input_spec(self):
   return {'num': lit_types.Scalar(),
           'cats': lit_types.CategoryLabel(vocab=['One', 'None'])}
예제 #21
0
파일: t5.py 프로젝트: oceanfly/lit
 def output_spec(self):
     spec = lit_types.remap_spec(self.model.output_spec(),
                                 self.FIELD_RENAMES)
     spec["rougeL"] = lit_types.Scalar()
     return spec
예제 #22
0
 def config_spec(self) -> types.Spec:
     return {
         INTERPOLATION_KEY:
         types.Scalar(min_val=5, max_val=200, default=IG_STEPS, step=1)
     }
예제 #23
0
 def spec(self) -> lit_types.Spec:
     """Dataset spec, which should match the model"s input_spec()."""
     return {
         "Sentence": lit_types.TextSegment(),
         "Token Index to Explain": lit_types.Scalar()
     }
예제 #24
0
 def input_spec(self) -> lit_types.Spec:
     return {
         "Sentence": lit_types.TextSegment(),
         "Token Index to Explain": lit_types.Scalar()
     }
예제 #25
0
 def input_spec(self) -> lit_types.Spec:
     return {
         'x_1': lit_types.Scalar(),
         'x_2': lit_types.Scalar(),
     }