Add char_quantize for AAPD (#173)

This commit is contained in:
Ashutosh-Adhikari
2019-01-29 09:52:20 -05:00
committed by Peng Shi
parent aec0826356
commit 84225d208c
+7
View File
@@ -9,6 +9,13 @@ from torchtext.vocab import Vectors
from datasets.reuters import clean_string, clean_string_fl, split_sents
def char_quantize(string, max_length=1000):
identity = np.identity(len(AAPDCharQuantized.ALPHABET))
quantized_string = np.array([identity[AAPDCharQuantized.ALPHABET[char]] for char in list(string.lower()) if char in AAPDCharQuantized.ALPHABET], dtype=np.float32)
if len(quantized_string) > max_length:
return quantized_string[:max_length]
else:
return np.concatenate((quantized_string, np.zeros((max_length - len(quantized_string), len(AAPDCharQuantized.ALPHABET)), dtype=np.float32)))
def process_labels(string):
"""