Approximate Text compression by training model?
Your problem can be solved with a hash map. If the dataset is very large, you can use an approximate hashmap. Examples of approximate hashmaps are Bloom Filters and Cuckoo Filters.