This is the official implementation of SAM4LTC
Here we provide:
- Source code for SAM4LTC in
model.py - Dependency utils in
utils.py - Manual annotated data in
/data/ - Use
data_loader.pyto load data - For training and testing use
train_test.py - For LLM refine, see
LLM_refine.py
For the data analysis part
- data of international migrations for people from Germany and the United States is in
analysis/data/ - data analysis code is in
analysis
Full data is released at HuggingFace: https://huggingface.co/datasets/Joy9562/WikiLifeTrajectory
Life trajectories of notable people convey essential messages for the wide work on human dynamics. These trajectories consist of (person, time, location, activity type) tuples, and may record when and where a person was born, passed away, went to school, started a job, got married, made a scientific discovery, finished a masterpiece, or won an election. However, current studies only cover very limited types of activities, such as births and deaths, which are easier to obtain -- there lack large-scale trajectories covering fine-grained activity types. After extracting (person, time, location) triples from Wikipedia with an existing tool, we formulate a problem of classifying these triples into 24 carefully-defined types, given the triples' textual contexts as complementary information. Apart from the difficulty of multi-classification, it is challenging since the entities consisting of the triples are often scattered afar in the context, with plenty of noise around. To better emphasize and aggregate the semantic relations between the focal triple entities and their related text, we make use of the syntactic graphs that bring the triple entities and their relevant information closer, and fuse them with the contextual embeddings to classify life trajectory activities. Meanwhile, we use LLM to refine the text from the crowd-sourced Wikipedia, resulting in more standard and unified syntactic graphs. Our framework outperforms baselines with an accuracy of 85.4%. With fine-grained trajectories of 589,193 people, we touch on grand narratives of human activities spanning 3 centuries. To facilitate relevant research, we make the code, the manually-labeled dataset, and the 3.8 million trajectory triples with classifications publicly available.
python >= 3.8.0
See requirements.txt
-
Life
- (1) Birth: Someone's life starts.
- (2) Death: Someone's life ends for any reason.
- (3) Marriage: Two people get married or engage.
- (4) Injure and Illness: Affairs related injures and illnesses such as receiving treatments.
- (5) Settlement: Someone resides in a certain place for a long or short period of time.
- (6) Education: Education events such as admission, enrollment, or graduation.
- (7) Give birth: A mother gives birth to a baby.
- (8) Accident: Unexpected events causing losses such as car accident, falling from a height.
- (9) Purchase and Sell: Generally involves purchasing and selling large assets such as real estate.
- (10) Divorce: Two people get divorced.
-
Career
- (11) Career: Event related to career changes such as being promoted or demoted, start or end a position.
-
Pro-Event (Professional Event)
- (12) Competition: Someone participates in a competition such as winning or losing a competition.
- (13) Performance: Someone plays a role in a performance, such as playing a role in a play, conducting or playing instruments in a concert.
- (14) Exhibition: Organizing personal exhibitions.
- (15) Creation: Do creative jobs, such as writing a book, recording an album and drawing a painting.
- (16) Campaign: Activities or efforts to hold a certain position such as running for president of a state or an institute.
- (17) Start org: Start an organization such as starting a bar and opening a company.
-
Contact
- (18) Meet: Small scale gatherings such as receiving interviews and encounters.
- (19) Assembly: Large scale gatherings for certain purposes such as attending a conference or award ceremony, giving a speech and protesting.
-
Justice
- (20) Justice: Everything related to justice such as arrests, trials, parole and testimony.
-
Attack
- (21) Attack: The act of destroying, damaging, or harming a target such as shooting, street fights and raids.
-
Movement
- (22) Movement: Someone moves from one place to another.
-
Military
- (23) Military: Life trajectory activities related to military events, such as a military action or serving in the army.
-
Other
- (24) Other: Life trajectory activities that are hard to be applied to any types above and almost meaningless such as staying in a certain place without further details.
Here are a sentence and a triple.
Sentence: {sentence}
Triple: {triple}
The triple indicates that who at what time is in somewhere described in the sentence.
Based on the triple and the sentence, which class does the sentence belong to?
Here are the classes you should choose from:
{label space}
For example, you should output Career when given the sentence and triple:
Sentence: From 1946 to 1948 he was flute professor at Kneller Hall.
Triple: (he, From 1946 to 1948, Kneller Hall)
You should output Military when given the sentence and triple:
Sentence: In 1961, Hoare's first mercenary action was in Katanga, a province trying to rebel from the newly independent Republic of the Congo.
Triple: (Hoare, 1961, Katanga)
You only need to return the class without any additional output.
Sentence: {sentence}
Question: What does {person} do at {time} in {location}?
Choose from the list:
{label space}
For example, you should choose Career when given
Sentence: From 1946 to 1948 he was flute professor at Kneller Hall.
Triple: (he, From 1946 to 1948, Kneller Hall)
You should choose Military when given
Sentence: In 1961, Hoare's first mercenary action was in Katanga, a province trying to rebel from the newly independent Republic of the Congo.
Triple: (Hoare, 1961, Katanga)
You only need to return the word in the list without any additional output.
You are a detective. Now you are given a triple of (person, time, location) and a sentence containing the triple.
Choose a proper activity type from the type list {label space} and return me the type.
Sentence: {sentence}
Triple: {triple}
For example, you should choose Career when given
Sentence: From 1946 to 1948 he was flute professor at Kneller Hall.
Triple: (he, From 1946 to 1948, Kneller Hall)
You should choose Military when given
Sentence: In 1961, Hoare's first mercenary action was in Katanga, a province trying to rebel from the newly independent Republic of the Congo.
Triple: (Hoare, 1961, Katanga)
You only need to return the type from the type list without any additional output.
Please rewrite the sentence according to the requirements.
Requirements:
1. Do not change the original meaning of the sentence
2. Use the exactly same words in [{person}, {time} {location}]
3. You can add, reduce, or modify some other words or phrases, such as verbs
4. The rewritten sentence cannot be the same as the original sentence
Sentence that needs to be rewritten: {sentence}.
You may remove some information unrelated to the given person, time and location.
You only need to return me the rewritten sentence without any additional output.
You are an editor. You will be provided a sentence describing person do something in time in location.
Please rewrite the sentence: {sentence}.
Highlight what {person} (person) do in {time} (time) and {location} (location).
You MUST use the exact word of
person: {person};
time: {time};
location: {location}.
You may remove some information unrelated to the given person, time and location.
You only need to return me the refined sentence without any additional output.