コード例 #1
0
 def __init__(self, feature_template=None, actionxid_map=None):
     self.feature_template = feature_template
     self.actionxid_map = actionxid_map
     if actionxid_map is not None:
         self.idxaction_map = reverse_dict(actionxid_map)
     # self.classifier = RandomForestClassifier(n_estimators=3, n_jobs=-1)
     self.classifier = LinearSVC(C=1.0, penalty='l2', loss='squared_hinge', dual=False, tol=1e-7, max_iter=10000)
コード例 #2
0
 def __init__(self,
              feature_template_level_0=None,
              feature_template_level_1=None,
              feature_template_level_2=None,
              relationxid_map=None):
     self.feature_template_level_0 = feature_template_level_0
     self.feature_template_level_1 = feature_template_level_1
     self.feature_template_level_2 = feature_template_level_2
     self.relationxid_map = relationxid_map
     if relationxid_map is not None:
         self.idxrelation_map = reverse_dict(relationxid_map)
     self.classifier_level_0 = LinearSVC(C=1.0,
                                         penalty='l1',
                                         loss='squared_hinge',
                                         dual=False,
                                         tol=1e-7)
     self.classifier_level_1 = LinearSVC(C=1.0,
                                         penalty='l1',
                                         loss='squared_hinge',
                                         dual=False,
                                         tol=1e-7)
     self.classifier_level_2 = LinearSVC(C=1.0,
                                         penalty='l1',
                                         loss='squared_hinge',
                                         dual=False,
                                         tol=1e-7)
コード例 #3
0
 def load(self, fname):
     """ Load models
     """
     with gzip.open(fname, 'rb') as fin:
         data = pickle.load(fin)
         self.classifier = data['action_clf']
         self.feature_template = data['feature_template']
         self.idxaction_map = data['idxaction_map']
         self.actionxid_map = reverse_dict(self.idxaction_map)
     print('Load action classifier from file: {} with {} features and {} actions.'.format(fname,
                                                                                          len(self.feature_template),
                                                                                          len(self.idxaction_map)))
コード例 #4
0
    def __init__(self, data_helper, config):
        super(NeuralClassifier, self).__init__()    
        self.data_helper = data_helper
        self.xidx_action_map = reverse_dict(data_helper.action_map)
        self.config = config
        self.init_embeddings()
        self.tokenizer = RobertaTokenizer.from_pretrained('distilroberta-base')
        self.bert = RobertaModel.from_pretrained('distilroberta-base')

        if self.config[UNTRAINED_ROBERTA]:
            # Initialize new model with the same config as distilroberta
            self.bert = RobertaModel(self.bert.config)
            
        self.out_classifier = nn.Sequential(
            nn.Linear(self.get_classifier_dim(), self.config[HIDDEN_DIM]),
            nn.GELU(),
            nn.Linear(self.config[HIDDEN_DIM], 4)
        )
コード例 #5
0
 def load(self, fname):
     """ Load models
             """
     with gzip.open(fname, 'rb') as fin:
         data = pickle.load(fin)
         self.classifier_level_0 = data['relation_clf_level_0']
         self.classifier_level_1 = data['relation_clf_level_1']
         self.classifier_level_2 = data['relation_clf_level_2']
         self.feature_template_level_0 = data['feature_template_level_0']
         self.feature_template_level_1 = data['feature_template_level_1']
         self.feature_template_level_2 = data['feature_template_level_2']
         self.idxrelation_map = data['idxrelation_map']
         self.relationxid_map = reverse_dict(self.idxrelation_map)
     print(
         'Load relation classifier from file: {} with {} features at level 0, '
         '{} features at level 1, {} features at level 2, and {} relations.'
         .format(fname, len(self.feature_template_level_0),
                 len(self.feature_template_level_1),
                 len(self.feature_template_level_2),
                 len(self.idxrelation_map)))