MCPcopy Index your code
hub / github.com/QData/TextAttack / CustomKerasModelWrapper

Class CustomKerasModelWrapper

examples/attack/attack_keras_parallel.py:68–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66
67
68class CustomKerasModelWrapper(ModelWrapper):
69 def __init__(self, model):
70 self.model = model
71
72 def __call__(self, text_input_list):
73 x_transform = []
74 for i, review in enumerate(text_input_list):
75 tokens = [x.strip(",") for x in review.split()]
76 BoW_array = np.zeros((NUM_WORDS,))
77 for word in tokens:
78 if word in vocabulary:
79 if vocabulary[word] < len(BoW_array):
80 BoW_array[vocabulary[word]] += 1
81 x_transform.append(BoW_array)
82 x_transform = np.array(x_transform)
83 prediction = self.model.predict(x_transform)
84 return prediction
85
86
87model = Sequential()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected