def run_svm_model_factory(): ##### YOUR CODE HERE return rel_ext.experiment(splits, model_factory=lambda: SVC(kernel='linear'), train_split='train', test_split='dev', featurizers=featurizers)
def test_experiment(featurizer, vectorize, corpus, kb): dataset = rel_ext.Dataset(corpus, kb) splits = dataset.build_splits( split_names=['tiny_train', 'tiny_dev', 'rest'], split_fracs=[0.05, 0.05, 0.90], seed=1) results = rel_ext.experiment(splits, train_split='tiny_train', test_split='tiny_dev', featurizers=[featurizer], vectorize=vectorize, verbose=False)
def run_svm_model_factory(): from sklearn.svm import SVC ##### YOUR CODE HERE model_factory = lambda: SVC(kernel='linear') svc_results = rel_ext.experiment(splits, train_split='train', test_split='dev', featurizers=featurizers, model_factory=model_factory, verbose=True) return svc_results
def run_svm_model_factory(): ##### YOUR CODE HERE from sklearn.svm import SVC glove_results = rel_ext.experiment( splits, train_split='train', test_split='dev', model_factory=(lambda: SVC(kernel='linear', max_iter=2)), featurizers=[glove_middle_featurizer], vectorize=False, # Crucial for this featurizer! verbose=True) return glove_results
# In[10]: featurizers = [simple_bag_of_words_featurizer] # In[11]: model_factory = lambda: LogisticRegression(fit_intercept=True, solver='liblinear') # In[12]: baseline_results = rel_ext.experiment(splits, train_split='train', test_split='dev', featurizers=featurizers, model_factory=model_factory, verbose=True) # Studying model weights might yield insights: # In[13]: rel_ext.examine_model_weights(baseline_results) # ### Distributed representations # # This simple baseline sums the GloVe vector representations for all of the words in the "middle" span and feeds those representations into the standard `LogisticRegression`-based `model_factory`. The crucial parameter that enables this is `vectorize=False`. This essentially says to `rel_ext.experiment` that your featurizer or your model will do the work of turning examples into vectors; in that case, `rel_ext.experiment` just organizes these representations by relation type. # In[14]:
# In[11]: featurizers = [simple_bag_of_words_featurizer] # In[12]: model_factory = lambda: LogisticRegression(fit_intercept=True, solver='liblinear') # In[13]: baseline_results = rel_ext.experiment(splits, train_split='train', test_split='dev', featurizers=featurizers, model_factory=model_factory, verbose=True) # Studying model weights might yield insights: # In[14]: rel_ext.examine_model_weights(baseline_results) # ### Distributed representations # # This simple baseline sums the GloVe vector representations for all of the words in the "middle" span and feeds those representations into the standard `LogisticRegression`-based `model_factory`. The crucial parameter that enables this is `vectorize=False`. This essentially says to `rel_ext.experiment` that your featurizer or your model will do the work of turning examples into vectors; in that case, `rel_ext.experiment` just organizes these representations by relation type. # In[15]: