mirror of
https://github.com/wassname/Castor.git
synced 2026-09-10 11:40:44 +08:00
Add char_quantize for AAPD (#173)
This commit is contained in:
committed by
Peng Shi
parent
aec0826356
commit
84225d208c
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user