def scoreABSA(self, content):
        predict_data = mydatasets.SemEval(self.text_field, self.as_field,
                                          self.sm_field, content)

        predict_iter = data.Iterator(predict_data,
                                     batch_size=len(predict_data),
                                     train=False,
                                     sort=False,
                                     sort_within_batch=False)
        labels, scores = self.absa_predict(predict_iter, self.absa_model,
                                           self.args_absa)
        labels, scores = self._reorder_sm_field(labels, scores)
        return [self.ontology[l] for l in labels], scores
Example #2
0
def load_semeval_data(text_field, as_field, sm_field, years, aspects, **kargs):
    if not args.atsa:
        semeval_train, semeval_test = get_semeval(years, aspects, args.r_l,
                                                  args.use_attribute)
    else:
        semeval_train, semeval_test = get_semeval_target(years, args.r_l)

    print(semeval_test)

    predict_test = [{
        "aspect":
        "food",
        "sentiment":
        "positive",
        "sentence":
        "good food in cute - though a bit dank - little hangout, but service terrible"
    }, {
        "aspect":
        "service",
        "sentiment":
        "negative",
        "sentence":
        "good food in cute - though a bit dank - little hangout, but service terrible"
    }, {
        "aspect":
        "service",
        "sentiment":
        "negative",
        "sentence":
        "good food in cute - though a bit dank - little hangout, but service terrible"
    }]
    predict_data = mydatasets.SemEval(text_field, as_field, sm_field,
                                      predict_test)

    train_data, dev_data, mixed_data = mydatasets.SemEval.splits_train_test(
        text_field, as_field, sm_field, semeval_train, semeval_test)

    text_field.build_vocab(train_data, dev_data)
    as_field.build_vocab(train_data, dev_data)
    sm_field.build_vocab(train_data, dev_data)
    train_iter, test_iter, mixed_test_iter, predict_iter = data.Iterator.splits(
        (train_data, dev_data, mixed_data, predict_data),
        batch_sizes=(args.batch_size, len(dev_data), len(mixed_data),
                     len(predict_data)),
        **kargs)

    return train_iter, test_iter, mixed_test_iter, predict_iter