Skip to content

Commit

Permalink
Add char_quantize for AAPD (castorini#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh-Adhikari authored and Impavidity committed Jan 29, 2019
1 parent aec0826 commit 84225d2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions datasets/aapd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

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):
"""
Expand Down

0 comments on commit 84225d2

Please sign in to comment.