Upload 3dec-3grams.pt
Browse filesimport numpy as np
from tqdm import tqdm
tqdm.pandas()
X_MIN, X_MAX, Y_MIN = -5.982, 5.928, -2.988
BASE_OFFSET = 0
# Changed multiplier to 1000
X_MAX_TOKEN = int(round((X_MAX - X_MIN) * 1000)) + BASE_OFFSET
X_MAX_TOKEN = 11910
Y_MAX_TOKEN = 19999
def tokenize_x_path_fast(float_list):
# 1. Convert to a NumPy array (using float32 to save initial memory)
arr = np.array(float_list, dtype=np.float32)
# 2. Vectorize the math, round, and aggressively cast to 32-bit integers
# Changed multiplier to 1000
tokens = np.round((arr - X_MIN) * 1000) + BASE_OFFSET
return tokens.astype(np.int32)
def tokenize_y_path_fast(float_list):
arr = np.array(float_list, dtype=np.float32)
# Changed multiplier to 1000
tokens = np.round((arr - Y_MIN) * 1000) + (X_MAX_TOKEN + 1)
return tokens.astype(np.int32)
# Overwrite the columns directly.
# Storing NumPy arrays in the DataFrame column takes drastically less memory than lists.
df['x_path'] = df['x_path'].progress_apply(tokenize_x_path_fast)
df['y_path'] = df['y_path'].progress_apply(tokenize_y_path_fast)
def detokenize_x_path_fast(token_list):
# 1. Ensure the input is a NumPy array of 32-bit integers
arr = np.array(token_list, dtype=np.int32)
# 2. Vectorize the reverse math and rounding
floats = np.round(((arr - BASE_OFFSET) / 1000.0) + X_MIN, 4)
# 3. Cast to float32 to keep memory usage strictly optimized
return floats.astype(np.float32)
def detokenize_y_path_fast(token_list):
arr = np.array(token_list, dtype=np.int32)
floats = np.round(((arr - (X_MAX_TOKEN + 1)) / 1000.0) + Y_MIN, 4)
return floats.astype(np.float32)
detokenize_x_path_fast([9692])
- 3dec-3grams.pt +3 -0
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:15f1bd3b02afbec7191b3930edbef5e5acaf5396ab529481d7cf342d8741243c
|
| 3 |
+
size 4132979077
|