UppercaseData
Loads the Uppercase data.
- The UppercaseData consists of three Datasets
- When loading, you need to specify
windowandalphabet_size. Ifalphabet_sizeis nonzero, it specifies the maximum number of alphabet characters, in which case that many most frequent characters will be used, and all other will be remapped to "<unk>". - Features are generated using a sliding window of a given size,
i.e., for a character, we include left
windowcharacters, the character itself, and rightwindowcharacters;2 * window + 1in total. - Each dataset (train/dev/test) has the following members:
__len__: the length of the text;text: the original text (of course lowercased in case of the test set);alphabet: an alphabet used bywindows;windows: a Pytorch Tensor with shape[size, 2 * window + 1]containing windows with indices of input lowercased characters;labels: a PyTorch Tensor with shape[size]containing 0/1 indicating whether the character of the corresponding window is lowercase/uppercase.
npfl138.datasets.uppercase_data.UppercaseData
Source code in npfl138/datasets/uppercase_data.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Dataset
Source code in npfl138/datasets/uppercase_data.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
__len__
__len__() -> int
Return the number of elements in the dataset.
Source code in npfl138/datasets/uppercase_data.py
97 98 99 | |
windows
property
windows: Tensor
A Tensor with shape [size, 2 * window + 1] and dtype torch.int64
containing windows with indices of input lowercased characters.
labels
property
labels: Tensor
A Tensor with shape [size] and dtype torch.int64 containing zeros and ones
indicating whether the character of the corresponding window is lowercase or uppercase.
__init__
Load the UppercaseData dataset, downloading it if necessary.
Parameters:
-
window(int) –The size of the sliding window of left and right characters to use for generating features.
-
alphabet_size(int, default:0) –If nonzero, the maximum number of alphabet characters (the most frequent ones will be used, others are remapped go "
"); if zero, all characters are used.
Source code in npfl138/datasets/uppercase_data.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
evaluate
staticmethod
Evaluate the predictions against the gold dataset.
Returns:
-
float–accuracy
Source code in npfl138/datasets/uppercase_data.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
evaluate_file
staticmethod
Evaluate the file with predictions against the gold dataset.
Returns:
-
float–accuracy
Source code in npfl138/datasets/uppercase_data.py
184 185 186 187 188 189 190 191 192 | |