API Documentation🔗
Text representation🔗
Core class🔗
Generate text representations of crystal structure for Language modelling.
Attributes:
Name | Type | Description |
---|---|---|
structure |
pymatgen structure |
Methods:
Name | Description |
---|---|
from_input |
a classmethod |
Source code in xtal2txt/core.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
apply_transformations()
🔗
Apply transformations to the structure.
Source code in xtal2txt/core.py
80 81 82 83 84 85 86 |
|
from_input(input_data, transformations=None)
classmethod
🔗
Instantiate the TextRep class object with the pymatgen structure from a cif file, a cif string, or a pymatgen Structure object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
Union[str, Structure]
|
A cif file of a crystal structure, a cif string, or a pymatgen Structure object. |
required |
Returns:
Name | Type | Description |
---|---|---|
TextRep |
TextRep
|
A TextRep object. |
Source code in xtal2txt/core.py
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 |
|
get_all_text_reps(decimal_places=2)
🔗
Returns all the Text representations of the crystal structure in a dictionary.
Source code in xtal2txt/core.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|
get_atom_sequences_plusplus(lattice_params=False, decimal_places=1)
🔗
Generating a string with the elements of composition inside the crystal lattice with the option to get the lattice parameters as angles (int) and lengths (float) in a string with a space between them
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lattice_params
|
bool
|
Whether to include lattice parameters or not. |
False
|
decimal_places
|
int
|
The number of decimal places to round to. |
1
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string representation of the crystal structure. |
Source code in xtal2txt/core.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
get_cif_string(format='symmetrized', decimal_places=3)
🔗
Generate CIF as string in multi-line format.
All float numbers can be rounded to the specified number (decimal_places). Currently supports two formats. Symmetrized (cif with symmetry operations and the least symmetric basis) ... and P1 (conventional unit cell , with all the atoms listed and only identity as symmetry operation).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The format of the CIF file. Can be "symmetrized" or "p1". |
'symmetrized'
|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The CIF string. |
Source code in xtal2txt/core.py
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 |
|
get_composition(format='hill')
🔗
Return composition in hill format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
format in which the composition is required. |
'hill'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The composition in hill format. |
Source code in xtal2txt/core.py
210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
get_coords(name='cartesian', decimal_places=3)
🔗
Return list of atoms in unit cell for with their positions in Cartesian or fractional coordinates as per choice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the coordinates. Can be "cartesian" or "fractional". |
'cartesian'
|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The list of atoms with their positions. |
Source code in xtal2txt/core.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
get_crystal_text_llm(permute_atoms=False)
🔗
Code adopted from https://github.com/facebookresearch/crystal-llm/blob/main/llama_finetune.py https://openreview.net/pdf?id=0r5DE2ZSwJ
Returns the representation as per the above citation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
permute_atoms
|
bool
|
Whether to permute the atoms in the unit cell. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The crystal-llm representation of the crystal structure. |
Source code in xtal2txt/core.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
get_lattice_parameters(decimal_places=3)
🔗
Return lattice parameters of unit cells in a crystal lattice: the lengths of the cell edges (a, b, and c) in angstrom and the angles between them (alpha, beta, and gamma) in degrees.
All float numbers can be rounded to a specific number (decimal_places).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
decimal_places
|
int
|
The number of decimal places to round to. |
3
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: The lattice parameters. |
Source code in xtal2txt/core.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
get_local_env_rep(local_env_kwargs=None)
🔗
Get the local environment representation of the crystal structure.
The local environment representation is a string that contains the space group symbol and the local environment of each atom in the unit cell. The local environment of each atom is represented as SMILES string and the Wyckoff symbol of the local environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_env_kwargs
|
dict
|
Keyword arguments to pass to the LocalEnvAnalyzer. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The local environment representation of the crystal structure. |
Source code in xtal2txt/core.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
get_requested_text_reps(requested_reps, decimal_places=2)
🔗
Returns the requested Text representations of the crystal structure in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
requested_reps
|
List[str]
|
The list of representations to return. |
required |
decimal_places
|
int
|
The number of decimal places to round to. |
2
|
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the requested text representations of the crystal structure. |
Source code in xtal2txt/core.py
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
get_robocrys_rep()
🔗
Source code in xtal2txt/core.py
286 287 288 289 290 291 292 |
|
get_slices(primitive=True)
🔗
Returns SLICES representation of the crystal structure. https://www.nature.com/articles/s41467-023-42870-7
Parameters:
Name | Type | Description | Default |
---|---|---|---|
primitive
|
bool
|
Whether to use the primitive structure or not. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The SLICE representation of the crystal structure. |
Source code in xtal2txt/core.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
get_wyckoff_positions()
🔗
Getting wyckoff positions of the elements in the unit cell as the combination of... number and letter.
Returns:
Name | Type | Description |
---|---|---|
str |
A multi-line string that contain elements of the unit cell along with their wyckoff position in each line. |
Hint
At the end of the string, there is an additional newline character.
Source code in xtal2txt/core.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
get_wycryst()
🔗
Obtaining the wyckoff representation for crystal structures that include
chemical formula space group number elements of the unit cell with their wyckoff positions.
Returns:
Name | Type | Description |
---|---|---|
str |
A multi-line string that contains the chemical formula, space group number, and the elements of the unit cell with their wyckoff positions. |
Source code in xtal2txt/core.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
get_zmatrix_rep(decimal_places=1)
🔗
Generate the Z-matrix representation of the crystal structure. It provides a description of each atom in terms of its atomic number, bond length, bond angle, and dihedral angle, the so-called internal coordinates.
Disclaimer: The Z-matrix is meant for molecules, current implementation converts atoms within unit cell to molecule. Hence the current implentation might overlook bonds acrosse unit cells.
Source code in xtal2txt/core.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
round_numbers_in_string(original_string, decimal_places)
staticmethod
🔗
Rounds float numbers in the given string to the specified number of decimal places using regex.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_string
|
str
|
The input string. |
required |
decimal_places
|
int
|
The number of decimal places to round to. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The string with the float numbers rounded to the specified number of decimal places. |
Source code in xtal2txt/core.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
updated_zmatrix_rep(zmatrix, decimal_places=1)
🔗
Replace the variables in the Z-matrix with their values and return the updated Z-matrix.
for eg: z-matrix from pymatgen
'N
N 1 B1 N 1 B2 2 A2 N 1 B3 2 A3 3 D3
B1=3.79
B2=6.54
....
is replaced to
'N
N 1 3.79 N 1 6.54 2 90 N 1 6.54 2 90 3 120 '
Args:
Zmatrix (bool): zmatrix multi line string as implemented in pymatgen.
decimal_places (int): The number of decimal places to round to.
Returns:
str: The updated Z-matrix representation of the crystal structure.
Source code in xtal2txt/core.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
Decoding🔗
DecodeTextRep
🔗
Source code in xtal2txt/decoder.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
cif_string_decoder_p1(input)
🔗
Returning a pymatgen structure out of a string format of a cif file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
Type | Description |
---|---|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
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 |
|
cif_string_decoder_sym(input)
🔗
Returning a pymatgen structure out of a string format of a symmetrized cif file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
Type | Description |
---|---|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
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 |
|
llm_decoder(input)
🔗
Returning pymatgen structure out of multi-line representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
str String to obtain the items needed for the structure. |
required |
Returns:
Type | Description |
---|---|
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
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 |
|
wyckoff_decoder(input, lattice_params=False)
🔗
Generating a pymatgen object from the output of the get_wyckoff_rep() method by using... pyxtal package. In this method, all data are extracted from the multi-line string of the... mentioned method. In pyxtal package, a 3D crystal is produced by specifying the dimensions, elements, composition of elements, space group, and sites as wyckoff positions of the elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lattice_params
|
bool
|
boolean To specify whether use lattice parameters in generating crystal structure. |
False
|
Returns:
Name | Type | Description |
---|---|---|
pmg_struc |
pymatgen.core.structure.Structure |
Source code in xtal2txt/decoder.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
MatchRep
🔗
Source code in xtal2txt/decoder.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
cif_string_matcher_p1(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from cif_string_decoder_p1 method out of string cif representation using fit() method of StructureMatcher module in pymatgen package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher
|
module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
Name | Type | Description |
---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
cif_string_matcher_sym(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from cif_string_decoder_sym method out of string cif representation. using fit() method of StructureMatcher module in pymatgen package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher
|
module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
Name | Type | Description |
---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
llm_matcher(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True)
🔗
To check if pymatgen object from the original cif file match with the generated pymatgen structure from llm_decoder method out of llm representation using fit() method of StructureMatcher module in pymatgen package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str String to obtain the items needed for the structure. |
required | |
StructureMatcher
|
module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
Returns:
Name | Type | Description |
---|---|---|
StructureMatcher |
).fit(
|
bool |
Source code in xtal2txt/decoder.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
wyckoff_matcher(ltol=0.2, stol=0.5, angle_tol=5, primitive_cell=True, scale=True, allow_subset=True, attempt_supercell=True, lattice_params=False)
🔗
To check if pymatgen object from the original cif file match with the generated... pymatgen structure from wyckoff_decoder method out of wyckoff representation... using fit() method of StructureMatcher module in pymatgen package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
StructureMatcher
|
module can be access in below link with its parameters
|
https://pymatgen.org/pymatgen.analysis.html#pymatgen.analysis.structure_matcher.StructureMatcher.get_mapping |
required |
lattice_params
|
bool
|
bool To specify using lattice parameters in the wyckoff_decoder method. |
False
|
Returns:
Name | Type | Description |
---|---|---|
StructureMatcher |
).fit_anonymous(
|
bool |
Source code in xtal2txt/decoder.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
Transformations🔗
Tokenizer🔗
CifTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
461 462 463 464 465 466 467 468 469 470 |
|
CompositionTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
428 429 430 431 432 433 434 435 436 437 |
|
CrysllmTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
494 495 496 497 498 499 500 501 502 503 |
|
NumTokenizer
🔗
Tokenize numbers as implemented in Regression Transformer. https://www.nature.com/articles/s42256-023-00639-z https://github.com/IBM/regression-transformer/tree/main
Source code in xtal2txt/tokenizer.py
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 |
|
__init__()
🔗
Tokenizer for numbers.
Source code in xtal2txt/tokenizer.py
87 88 89 |
|
convert_tokens_to_float(tokens)
staticmethod
🔗
Converts tokens representing a float value into a float. NOTE: Expects that non-floating tokens are strippped off
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokens
|
List[str]
|
List of tokens, each representing a float. E.g.: ['0_0', '.', '9-1_', '3-2_', '1-3_'] |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Float representation for the list of tokens. |
Source code in xtal2txt/tokenizer.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
convert_tokens_to_string(tokens)
🔗
Converts tokens to string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokens
|
List[str]
|
List of tokens. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
String representation of the tokens. |
Source code in xtal2txt/tokenizer.py
156 157 158 159 160 161 162 163 164 165 |
|
num_matcher(text)
🔗
Extract numbers from a sentence and replace them with tokens.
Source code in xtal2txt/tokenizer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
tokenize(text)
🔗
Tokenization of numbers as in RT. '0.9' -> '0_0', '.', '9-1_'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
number as string to be tokenized. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
extracted tokens. |
Source code in xtal2txt/tokenizer.py
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 |
|
RobocrysTokenizer
🔗
Tokenizer for Robocrystallographer. Would be BPE tokenizer. trained on the Robocrystallographer dataset. TODO: Implement this tokenizer.
Source code in xtal2txt/tokenizer.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
|
SliceTokenizer
🔗
Bases: Xtal2txtTokenizer
Source code in xtal2txt/tokenizer.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
|
convert_tokens_to_string(tokens)
🔗
Converts tokens to string.
Source code in xtal2txt/tokenizer.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
token_analysis(list_of_tokens)
🔗
Takes tokens after tokenize and returns a list with replacing the tokens with their MASK token. The token type is determined from the dict declared globally, and the token is replaced with the corresponding MASK token.
Source code in xtal2txt/tokenizer.py
395 396 397 398 399 400 401 402 403 404 |
|
Models🔗
FinetuneLLamaSFT
🔗
Class to perform finetuning of a language model. Initialize the FinetuneModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/llama_sft.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/llama_sft.py
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
FinetuneLLama
🔗
Class to perform finetuning of LLama using a regression head.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/llama.py
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
evaluate()
🔗
Evaluate the fine-tuned model on the test dataset.
Source code in src/mattext/models/llama.py
249 250 251 252 253 |
|
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/llama.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
smart_tokenizer_and_embedding_resize(special_tokens_dict, llama_tokenizer, model)
🔗
Resize tokenizer and embedding.
Note: This is the unoptimized version that may make your embedding size not be divisible by 64.
Source code in src/mattext/models/llama.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
PotentialModel
🔗
Bases: TokenizerMixin
Class to perform finetuning of a language model on the hypothetical potential task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
DictConfig
|
Configuration for the fine-tuning. |
required |
local_rank
|
int
|
Local rank for distributed training. Defaults to None. |
None
|
Source code in src/mattext/models/potential.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
evaluate()
🔗
Evaluate the fine-tuned model on the test dataset.
Source code in src/mattext/models/potential.py
169 170 171 172 173 |
|
finetune()
🔗
Perform fine-tuning of the language model.
Source code in src/mattext/models/potential.py
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 |
|
PretrainModel
🔗
Bases: TokenizerMixin
Class to perform pretraining of a language model.
Source code in src/mattext/models/pretrain.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 |
|
pretrain_mlm()
🔗
Performs MLM pretraining of the language model.
Source code in src/mattext/models/pretrain.py
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 |
|