Skip to content

Commit

Permalink
support for compressed and uncompressed arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
calebchiam committed May 30, 2020
1 parent eb34cfb commit 987b703
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions convokit/paired_prediction/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from random import choice, shuffle
from pandas import DataFrame
import numpy as np
from scipy.sparse import csr_matrix, vstack
from scipy.sparse import csr_matrix, vstack, issparse
from convokit.classifier.util import extract_feats_from_obj


Expand Down Expand Up @@ -36,7 +36,12 @@ def generate_bow_paired_X_y(pair_orientation_feat_name, pair_id_to_objs, vector_

X.append(diff)

return vstack(X), np.array(y)
if issparse(X[0]): # for csr_matrix
X = vstack(X)
else: # for non-compressed numpy arrays
X = np.vstack(X)

return X, np.array(y)


def generate_paired_X_y(pred_feats, pair_orientation_feat_name, pair_id_to_objs):
Expand Down
8 changes: 4 additions & 4 deletions convokit/text_processing/textProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def transform(self, corpus: Corpus) -> Corpus:

def transform_utterance(self, utt, override_input_filter=False):
"""
Computes per-utterance attributes of an individual utterance or string. For utterances which do not contain all of the `input_field` attributes as specified in the constructor, or for utterances which return `False` on `input_filter`, this call will not annotate the utterance. For strings, will convert the string to an utterance and return the utterance, annotating it if `input_field` is not set to `None` at initialization.
Computes per-utterance attributes of an individual utterance or string. For utterances which do not contain all of the `input_field` attributes as specified in the constructor, or for utterances which return `False` on `input_filter`, this call will not annotate the utterance. For strings, will convert the string to an utterance and return the utterance, annotating it if `input_field` is not set to `None` at initialization.
:param utt: utterance or a string
:param override_input_filter: ignore `input_filter` and compute attribute for all utterances
:return: the utterance
:param utt: utterance or a string
:param override_input_filter: ignore `input_filter` and compute attribute for all utterances
:return: the utterance
"""

if isinstance(utt, str):
Expand Down

0 comments on commit 987b703

Please sign in to comment.