<jupyter_start><jupyter_text>Use MEGNet element features for MP Ef regression<jupyter_code>from pymatgen.core import Element

from megnet.data.crystal import get_elemental_embeddings
embeddings = get_elemental_embeddings()
embeddings = {Element(i).Z: j for i, j in embeddings.items()}
describer = SiteElementProperty(embeddings, output_weights=True)
model = AtomSets(describer=describer,  # output weights gives element fractions
                 is_embedding=False,  # we are using the pre-trained element embeddings
                 compile_metrics=["mae"],
                 loss="mse",
                 is_classification=False
                )

features = describer.transform(df['formula'][:80])
model.fit(features, df['Ef'][:80], epochs=10)
test_features = describer.transform(df['formula'][80:])
loss, metric = model.evaluate(test_features, df['Ef'][80:], True)
print(f"The MAE is {metric:.3f} eV/atom")<jupyter_output>The MAE is 1.413 eV/atom<jupyter_text>No transfer learning for Ef regression<jupyter_code>describer = SiteElementProperty(output_weights=True)
model = AtomSets(describer=describer,
                 is_embedding=True,
                 compile_metrics=["mae"],
                 loss="mse",
                 is_classification=False
                )

features = describer.transform(df['formula'][:80])
model.fit(features, df['Ef'][:80], epochs=10)
test_features = describer.transform(df['formula'][80:])
loss, metric = model.evaluate(test_features, df['Ef'][80:], True)
print(f"The MAE is {metric:.3f} eV/atom")<jupyter_output>The MAE is 1.859 eV/atom<jupyter_text>Use MEGNet element features for metallicity classification<jupyter_code>df_metal = pd.read_csv("mp_is_metal_100.csv")
df_metal
describer = SiteElementProperty(embeddings, output_weights=True)
model = AtomSets(describer=describer,  # output weights gives element fractions
                 is_embedding=False,  # we are using the pre-trained element embeddings
                 compile_metrics=["AUC"],
                 loss="binary_crossentropy",
                 is_classification=True,
                )

features = describer.transform(df['formula'][:80])
model.fit(features, df['is_metal'][:80], epochs=10)
test_features = describer.transform(df['formula'][80:])
loss, metric = model.evaluate(test_features, df['is_metal'][80:], True)
print(f"The AUC is {metric:.3f}")<jupyter_output>The AUC is 0.677<jupyter_text>No transfer learning for metallicity classification<jupyter_code>describer = SiteElementProperty(output_weights=True)
model = AtomSets(describer=describer,
                 is_embedding=True,
                 compile_metrics=["AUC"],
                 loss="binary_crossentropy",
                 is_classification=True
                )

features = describer.transform(df['formula'][:80])
model.fit(features, df['is_metal'][:80], epochs=10)
test_features = describer.transform(df['formula'][80:])
loss, metric = model.evaluate(test_features, df['is_metal'][80:], True)
print(f"The AUC is {metric:.3f}")<jupyter_output>The AUC is 0.525
{'fraction_non_alphanumeric': 0.1260697827518104, 'fraction_numerical': 0.020737327188940093, 'mean_word_length': 4.133445945945946, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '431293', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1029, 'n_tokens_neox': 930, 'n_words': 179, 'path': 'notebooks/atomsets/composition_models.ipynb', 'repo_name': 'sgbaird/maml', 'size': '3038'}