SocialComplexityLab/life2vec
Fork: 69 Star: 488 (更新于 2024-11-15 00:05:00)
license: MIT
Language: Jupyter Notebook .
最后发布版本: v1.0.0 ( 2023-11-13 21:28:09)
Using Sequences of Life-events to Predict Human Lives
This repository contains code for the Using Sequences of Life-events to Predict Human Lives (life2vec) paper. We have only one webpage related to the project (life2vec.dk), and we do not have any specialized Facebook, Tweeter accounts, etc. For more information refer to the FAQ.
Basic Implementation of life2vec
We will keep keep this repository as is. We are publishing some components of the life2vec model in separate repositories:
- a basic implemenetation of the model is published in carlomarxdk/life2vec-light - it contains a code to run a pretraining with the dummy data,
- a class distance weigthed cross-entropy loss is published in carlomarxdk/cdw-cross-entropy-loss - this loss was used in the Extraversion Traits Prediction task.
Source Code
This repository contains scripts and several notebooks for data processing, life2vec training, statistical analysis, and visualization. The model weights, experiment logs, and associated model outputs can be obtained in accordance with the rules of Statistics Denmark's Research Scheme.
Paths (e.g., to data, or model weights) were redacted before submitting scripts to GitHub.
Overall Structure
We use Hydra to run the experiments. The /conf
folder contains configs for the experiments:
-
/experiment
contains configurationyaml
for pretraining and finetuning, -
/tasks
contain the specification for data augmentation in MLM, SOP, etc., -
/trainer
contains configuration for logging (not used) and multithread training (not used), -
/data_new
contains configs for data loading and processing, -
/datamodule
contains configs that specify how data should be loaded to PyTorch and PyTorch Lightning -
callbacks.yaml
specifies the configuration for the PyTorch Lightning Callbacks , -
prepare_data.yaml
can be used to run data preprocessing.
The /analysis
folder contains ipynb
notebooks for post-hoc evaluation:
-
/embedding
contains the analysis of the embedding spaces, -
/metric
contains notebooks for the model evaluation, -
/visualisation
contains notebooks for the visualisation of spaces, -
/tcav
includes TCAV implementation, -
/optimization
hyperparameter tuning.
The source folder, /src
, contains the data loading and model training codes. Due to the specifics of the hydra
package. Here is the overview of the /src
folder:
- The
/src/data_new
contains scripts to preprocess data as well as prepare data to load into the PyTorch or PyTorch Lightning, - The
/src/models
contains the implementation of baseline models, - The
/src/tasks
include code specific to the particular task, aka MLM, SOP, Mortality Prediction, Emigration Prediction, etc. -
/src/tranformer
contains the implementation of the life2vec model:- In
performer.py
, we overwrite the functionality of theperformer-pytorch
package, - In
cls_model.py
, we have an implementation of the finetuning stage for the binary classification tasks (i.e. early mortality and emigration), - In
hexaco_model.py
, we have an implementation of the finetuning stage for the personality nuance prediction task, -
models.py
contains the code for the life2vec pretraining (aka the base life2vec model), - The
transformer_utils.py
contains the implementation of custom modules, like losses, activation functions, etc. - The
metrics.py
contains code for the custom metric, - The
modules.py
,attention.py
,att_utils.py
, andembeddings.py
contain the implementation of modules used in the transformer network (aka life2vec encoders).
- In
Scripts such as train.py
, test.py
, tune.py
, and val.py
used to run a particular stage of the training, while prepare_data.py
was used to run the data processing (see below the example).
Run the script
To run the code, you would use the following commands:
# run the pretraining:
HYDRA_FULL_ERROR=1 python -m src.train experiment=pretrain trainer.devices=[7]
# finetuning of the hyperparamaters (for the pretraining)
HYDRA_FULL_ERROR=1 python -m src.train experiment=pretrain_optim
# assemble general dataset (GLOBAL_SET)
HYDRA_FULL_ERROR=1 python -m src.prepare_data +data_new/corpus=global_set target=\${data_new.corpus}
# assemble dataset for the mortality prediction task (SURVIVAL_SET)
HYDRA_FULL_ERROR=1 python -m src.prepare_data +data_new/population=survival_set target=\${data_new.population}
# assemble labour source
python -m src.prepare_data +data_new/sources=labour target=\${data_new.sources}
# run emigration finetuning
HYDRA_FULL_ERROR=1 python -m src.train experiment=emm trainer.devices=[0] version=0.01
Another Code Contributors
- Søren Mørk Hartmann.
How to cite
Nature Computational Science
@article{savcisens2024using,
author={Savcisens, Germans and Eliassi-Rad, Tina and Hansen, Lars Kai and Mortensen, Laust Hvas and Lilleholt, Lau and Rogers, Anna and Zettler, Ingo and Lehmann, Sune},
title={Using sequences of life-events to predict human lives},
journal={Nature Computational Science},
year={2024},
month={Jan},
day={01},
volume={4},
number={1},
pages={43-56},
issn={2662-8457},
doi={10.1038/s43588-023-00573-5},
url={https://doi.org/10.1038/s43588-023-00573-5}
}
ArXiv Preprint
@article{savcisens2023using,
title={Using Sequences of Life-events to Predict Human Lives},
DOI = {arXiv:2306.03009},
author={Savcisens, Germans and Eliassi-Rad, Tina and Hansen, Lars Kai and Mortensen, Laust and Lilleholt, Lau and Rogers, Anna and Zettler, Ingo and Lehmann, Sune},
year={2023}
}
Code
@misc{life2vec_code,
author = {Germans Savcisens},
title = {Official code for the "Using Sequences of Life-events to Predict Human Lives" paper},
note = {GitHub: SocialComplexityLab/life2vec},
year = {2023},
howpublished = {\url{https://doi.org/10.5281/zenodo.10118621}},
}
最近版本更新:(数据更新于 2024-10-14 05:19:37)
2023-11-13 21:28:09 v1.0.0
SocialComplexityLab/life2vec同语言 Jupyter Notebook最近更新仓库
2024-11-15 05:39:53 KindXiaoming/pykan
2024-11-11 10:53:33 microsoft/autogen
2024-10-30 14:24:30 neo4j-labs/llm-graph-builder
2024-10-09 04:20:42 Arize-ai/phoenix
2024-10-03 01:07:52 langchain-ai/langchain
2024-10-02 03:17:33 udlbook/udlbook