11institutetext: ARiSE Labs at Bosch, Bangalore, India 11email:
<EMAIL_ADDRESS>
# LLM2KB: Constructing Knowledge Bases using instruction tuned context aware
Large Language Models

Anmol Nayak∗ Hari Prasad Timmapathini∗

###### Abstract

The advent of Large Language Models (LLM) has revolutionized the field of
natural language processing, enabling significant progress in various
applications. One key area of interest is the construction of Knowledge Bases
(KB) using these powerful models. Knowledge bases serve as repositories of
structured information, facilitating information retrieval and inference
tasks. Our paper proposes LLM2KB, a system for constructing knowledge bases
using large language models, with a focus on the Llama 2 architecture and the
Wikipedia dataset. We perform parameter efficient instruction tuning for
Llama-2-13b-chat and StableBeluga-13B by training small injection models that
have only $\approx$0.05 % of the parameters of the base models using the Low-
Rank Adaptation (LoRA) technique. These injection models have been trained
with prompts that are engineered to utilize Wikipedia page contexts of subject
entities fetched using a Dense Passage Retrieval (DPR) algorithm, to answer
relevant object entities for a given subject entity and relation. Our best
performing model achieved an average F1 score of 0.6185 across 21 relations in
the LM-KBC challenge held at the ISWC 2023 conference.

###### Keywords:

Large Language Models Knowledge Base Instruction Tuning Parameter Efficient
Fine Tuning In-context learning.

**footnotetext: Both authors contributed equally to this work++footnotetext:
Submission: https://github.com/anmoln94/Team_LLM2KB_LM-KBC-2023

##  1 Introduction

The rapid advancements in natural language processing (NLP) have propelled the
development of large language models, revolutionizing the way machines
understand and generate human language. One of the pivotal applications of
these sophisticated models lies in the construction of knowledge bases, which
serve as repositories of structured information essential for a multitude of
NLP tasks, including information retrieval, question answering, and knowledge
inference.

Knowledge bases hold immense potential for enhancing machine understanding of
the world, but constructing them manually is a laborious and time-consuming
process. However, the emergence of large language models such as GPT-4 [1],
Llama 2 [2] Stable Beluga 2 [3], has opened new possibilities for knowledge
base construction. These models possess extensive linguistic knowledge and
factual knowledge that can be leveraged for automated entity recognition,
relation extraction, and knowledge representation.

One of the prominent sources for constructing knowledge bases is the vast
repository of human-curated information available on Wikipedia. This publicly
accessible dataset contains an extensive wealth of knowledge on diverse
topics, making it an ideal resource for building comprehensive knowledge
bases. Integrating Wikipedia data into knowledge bases allows for a wider
coverage and a well-rounded understanding of various domains.

Nevertheless, the success of constructing knowledge bases using large language
models hinges on the ability to fine-tune these models effectively.
Traditional fine-tuning methods often suffer from scalability issues and
demand an excessive amount of computational resources. However, recent
advancements in parameter-efficient fine-tuning techniques, like LoRA (Low-
Rank Adaptation) [4], have showcased promising results in reducing the
complexity and computational requirements while preserving model performance.
By efficiently fine-tuning large language models, researchers can unlock their
true potential in knowledge base construction and empower them to comprehend
and generate valuable information.

In this paper, we describe our system developed for Track 2 of the LM-KBC
challenge at ISWC 2023 [5], which focuses on using language models of any size
for knowledge base construction. Given an input subject-entity (s) and
relation (r), the system attempts to predict all the correct disambiguated
object-entities.

##  2 Related Work

The inquiry into the potential of language models (LM) in replacing or aiding
the creation and curation of knowledge bases was initially posed by [6] and
later explored by other researchers [7]. The LAMA dataset which probes
relational knowledge in language models through masked language modeling tasks
to complete cloze-style sentences was introduced in [6].

While the initial study utilized manually designed prompts to probe the
language model, subsequent research has demonstrated the advantages of
automatically learning prompts. Various methods have emerged to mine prompts
from large text corpora and select the most effective ones [8, 9].
Additionally, prompts can be directly learned through back-propagation [10,
11], showcasing how learned prompts can enhance the performance on LAMA tasks.

The performance of probing language models can be significantly improved
through various approaches, such as directly learning continuous embeddings
for prompts [12, 13], fine-tuning the LM on the training data [14], or few-
shot learning [15]. The authors demonstrate that combining few-shot examples
with learned prompts achieves the best probing results.

While probing language models has been extensively studied in the NLP
community, the idea of utilizing language models to support knowledge graph
curation has not received adequate attention [7]. Some works have demonstrated
the combination of language models with knowledge bases to complete query
results effectively [16]. Others have investigated how language models can be
employed to identify errors in knowledge graphs [17] or explored using
language models to weigh KG triples from ConceptNet for measuring semantic
similarity. [18] have showcased the utility of language models in entity
typing by predicting entity classes using language model-based approaches.

Further, the LM-KBC challenge at ISWC 2022 [19] produced interesting
submissions on using LM for KB construction. [20] developed a system that
performed task-specific pre-training of BERT, used prompt decomposition for
generating candidate objects progressively, and employed adaptive thresholds
for candidate selection. They utilized additional knowledge triples from
Wikidata KB for BERT pre-training and experimented with cloze-style prompts,
but found that masking nearby tokens of the object-entity did not improve
performance. By mining prompts from Wikipedia and using an ensemble approach
with averaged voting, they achieved final object-entity predictions. They also
proposed sticky thresholds for candidate selection based on likelihood
comparison.

[21] introduces the ProP system, which employs GPT-3 [22] under a few-shot
setting for knowledge base (KB) construction. ProP uses various prompting
techniques, including manual prompt creation and question-style prompts, to
verify the accuracy of GPT-3 generated claims. They utilize context examples
with specific properties, such as varying answer sets, subjects with empty
answer sets, and question-answer pairs, to train the model effectively.

[23] utilized manual prompts, generated from three automated sources, and
applied ensemble learning for final predictions. Descriptive information from
Wikidata was used to create prompts through ”middle-word”, ”dependency-based”
and ”paraphrasing-based” strategies. The BERT-large model was probed using
these prompts, and the five most frequent and likely objects were selected
from the ensemble. Before selecting the top-5 objects, the candidate list was
post-processed by removing stopwords. The threshold for candidate selection
was treated as a hyper-parameter, and its tuning was done separately for each
relation on the train dataset.

[24] proposes manual prompts tailored for each relation to probe the BERT-
large model, utilizing semantics and domain knowledge. They uniquely utilize
word co-occurrences in context to design prompts and reason about the
relationship between subjects and objects in questions to optimize prompt
design for various relations, observing improvements through simple
modifications like changing articles in the prompt for the ”plays-instrument”
relation. [25] conducts experiments with different manual prompts and
candidate selection thresholds for each relation during BERT model probing.
They also investigate the impact of selecting a larger number of options in
the object list (100, 150, 180, or 200) on overall performance. Additionally,
they create an ensemble of their manually crafted prompts to further enhance
the probing results.

##  3 The LM-KBC 2023 Challenge

###  3.1 Description

The LM-KBC 2023 challenge is centered around constructing disambiguated
knowledge bases from language models based on given subjects and relations.
Unlike existing probing benchmarks like LAMA [6], LM-KBC 2023 does not assume
any specific relation cardinalities, allowing subjects to have zero, one, or
multiple object-entities. Submissions are required to not only rank predicted
surface strings but also materialize disambiguated entities in the output. The
evaluation process involves calculating precision and recall for each test
instance compared to the ground-truth values. For every relation, the macro-
averaged precision, recall and f1-score are computed. The final ranking of
participating systems is determined based on the average F1-score across all
21 relations. Formally, the task involves predicting all correct object-
entities (o1, o2, …, ok) using LM probing given the input subject-entity (s)
and relation (r).

The challenge comes with two tracks:

  * •

Track 1: A small-model track with low computational requirements (<1 billion
parameters) and usage of context is not allowed.

  * •

Track 2: An open track, where participants can use any LM of their choice and
usage of context is allowed.

###  3.2 Dataset

The LM-KBC dataset comprises both training and validation sets, encompassing
21 diverse relations. A test set containing only subject entities and
relations was released towards the end of the challenge. The train, validation
and test set each comprise of 1940 records. Each relation covers distinct
subject-entities, and for each subject-relation pair, a comprehensive list of
ground truth object-entities is provided. Each row in the dataset files
includes the subject-entity ID, subject-entity name, a list of all possible
object-entity IDs, a list of all possible object-entities, and the
corresponding relation. The entity IDs correspond to the Wikidata ID. To
perform instruction fine-tuning on the models, we consume the provided dataset
and generate training samples in 2 ways:

  * •

Method 1: First, the Train set and Validation set are combined to produce a
super set. For each record, we begin generating a separate instruction tuning
dataset (see Section 4.2 for details on the Prompts) by slot filling Prompt 1
and 2. Thus, each record in the super set produces 2 samples for the
instruction tuning dataset. Then, for each ObjectEntity in the record we slot
fill Prompt 3, which additionally generates as many new samples for the
instruction tuning dataset as there are object entities. The generated
instruction tuning dataset is shuffled and we keep aside 1000 samples for
validation and the 14310 samples are used for training.

  * •

Method 2: This method also utilises Prompt 1,2 and 3 however the instruction
tuning training dataset is generated only using the Train set, while the
entire Validation set is used to generate the instruction tuning validation
dataset. 7666 samples were used for training and 7644 samples were used for
validation.

Figure 1: LLM2KB System Architecture.

##  4 LLM2KB System Description

###  4.1 Components

####  4.1.1 Large Language Model:

We have selected ’Llama-2-13b-chat’ model from Meta AI and ’StableBeluga-13B’
model from Stability AI as our base models, as they have been fine-tuned for
instruction following, are open source and have achieved state-of-the-art
performance on numerous benchmarks. Both the models are fine-tuned versions of
the original Llama-2-13b base model and have 13 billion parameters.
Llama-2-13b-chat is fine-tuned for chat instructions using Supervised Fine
Tuning (SFT) and Reinforcement Learning with Human Feedback (RLHF).
StableBeluga-13B is a Llama-2-13b model fine-tuned on an Orca [26] style
instruction dataset.

####  4.1.2 Context Retrieval Model:

We have selected Dense Passage Retrieval (DPR) from Meta AI [27] for subject
entity context retrieval. DPR comprises a collection of tools and models used
in state-of-the-art open-domain Question and Answer research. We used ’dpr-
ctx_encoder-single-nq-base’ for encoding questions and ’dpr-ctx_encoder-
multiset-base’ for encoding contexts. Further, we store the dense vectors of
the contexts in a Facebook AI Similarity Search (FAISS) vector store for fast
search and retrieval.

####  4.1.3 Entity Disambiguation:

Once we have predicted an object entity, we send the object entity text to the
Wikidata API to fetch potential disambiguated entities. The results returned
by Wikidata are then given to the LLM to pick the correct disambiguated
entity.

###  4.2 LLM prompts

We created 4 different prompts based on the format of each of the base models,
where Prompt 1,2 and 3 are used for performing instruction tuning and Prompt 4
is used only during inference for in-context learning. Note: During inference,
Prompt 1,2 and 3 are trimmed after [/INST] for Llama-2-13b-chat and after ###
Assistant\nAnswer: for StableBeluga-13B. Instruction tuning is a technique to
perform supervised fine tuning of models to make them learn to produce valid
responses for specific instructions. In our case, the instruction tuning helps
the model in 2 ways:

  1. 1.

Learn to answer relevant object entities for a given question (see Table 1)
with and without context. This is achieved with Prompt 1 and Prompt 2.

  2. 2.

Given a predicted surface string of an object entity, learn to pick the
correct Wikipedia entity title (but not Wikidata ID) from a list of candidate
options. This is achieved with Prompt 3.

In-context learning is a method where few examples of the expected output are
supplied in the prompt and the model uses them to produce an output in a
similar fashion. Prompt 1,2 and 3 are expecting the LLM to produce an answer
in a Python list of string format, however we noticed that the model sometimes
produces a syntactically incorrect list. Hence, we use Prompt 4 to demonstrate
to the LLM an incorrect format Answer vs. correct format Answer.

####  4.2.1 Llama-2-13b-chat prompts:

  1. 1.

<s>[INST] <<SYS>>\n You are a helpful, respectful and honest assistant. Your
answers should be crisp, short and not repititive.\n Give valid wikipedia page
titles in the answer. The answer should be in a python list of string
format.\n If you dont know the answer from both the given context and your
past knowledge, answer should just be a python empty list.\n\n <</SYS>>\n
context: ’{context}’\n\n {question} [/INST] Answer: {answer} </s>

In this prompt, the {question} variable is formed by first picking the
relevant question corresponding to the relation (see Table 1) and then
replacing the subject entity of the data row in the {question}. {context}
variable is formed by concatenating the strings of the top 2 contexts returned
by the DPR system for the given {question}. It is important to note that to
fetch the top 2 contexts, the DPR context encoder is only fed the Wikipedia
page textual content of the subject entity and we do not use the content of
the Wikipedia Infobox (found at the top right corner of a Wikipedia page),
since the Infobox already contains semi-structured information about an entity
which would defeat the purpose of using a LLM. The {answer} variable is formed
by replacing the object entities of the data row.

  2. 2.

<s>[INST] <<SYS>>\n You are a helpful, respectful and honest assistant. Your
answers should be crisp, short and not repititive.\n Give valid wikipedia page
titles in the answer. The answer should be in a python list of string
format.\n If you dont know the answer from both the given context and your
past knowledge, answer should just be a python empty list.\n\n <</SYS>>\n
context: ”\n\n {question} [/INST] Answer: {answer} </s>

In this prompt, the {question} variable and {answer} variable are formed in
the same method as the previous prompt, however we do not supply any context.

  3. 3.

<s>[INST] <<SYS>>\n You are a helpful, respectful and honest assistant. Your
answers should be crisp, short and not repititive.\n Choose an answer from the
options in the context.\n If you dont know the answer from the given context,
answer should just be a python empty list.\n <</SYS>>\n context:
’{options}’\n\n {question} [/INST] Answer: {answer} </s>

In this prompt, the {question} variable is formed in the same method as the
previous prompts, the {options} variable is the list of titles for the
Wikidata entities returned by the API when queried with a given object entity
text. Each separate object entity will lead to 1 unique training sample. For
e.g. if a data row has 4 object entities, then we will generate 4 separate
training samples for it. The {answer} variable is the title of the response
entity which has the same Wikidata ID as the object entity.

  4. 4.

<s>[INST] <<SYS>>\n Example 1: Wrong Format: [’People’s Republic of China’,
’Laos’, ’Thailand’, ’India’, ’Bangladesh’]”].

Correct Format: Answer: ”People’s Republic of China”, ”Laos”,

”Thailand”, ”India”, ”Bangladesh”] </s>\n

Example 2: Wrong Format: [’Artibonite’, ’Nord-Est Department’, ’South
Department’,’West Department’, ’Centre Department’,

’Grand’Anse Department’, ’North Department’]. Correct Format: Answer:
”Artibonite”, ”Nord-Est Department”, ”South Department”, ”West Department”,
”Centre Department”, ”Grand’Anse Department”, ”North Department”] </s>\n

Example 3: Wrong Format: [’book’s and page’s’]. Correct Format: Answer:
[”book’s and page’s”] </s>\n Your answer should only be a valid python list of
string format. Do not give any explainations.\n <</SYS>>\n Use the examples to
convert {answer} into a correct python list. [/INST] Answer:

Once an answer is generated from Prompt 1, 2 or 3, it is used as the {answer}
variable in this prompt to format the answer in a correct Python list of
string format.

Table 1: Questions corresponding to each relation. Relation | Question
---|---
BandHasMember | Who are the members of _?
CityLocatedAtRiver | Which river is _ located at?
CompanyHasParentOrganisation | What is the parent organization of _?
CompoundHasParts | What are the components of _?
CountryBordersCountry | Which countries border _?
CountryHasOfficialLanguage | What is the official language of _?
CountryHasStates | Which states are part of _?
FootballerPlaysPosition | What position does _ play in football?
PersonCauseOfDeath | What caused the death of _?
PersonHasAutobiography | What is the title of _’s autobiography?
PersonHasEmployer | Who is _’s employer?
PersonHasNoblePrize | In which field did _ receive the Nobel Prize?
PersonHasNumberOfChildren | How many children does _ have?
PersonHasPlaceOfDeath | Where did _ die?
PersonHasProfession | What is _’s profession?
PersonHasSpouse | Who is _ married to?
PersonPlaysInstrument | What instrument does _ play?
PersonSpeaksLanguage | What languages does _ speak?
RiverBasinsCountry | In which country can you find the _ river basin?
SeriesHasNumberOfEpisodes | How many episodes does the series _ have?
StateBordersState | Which states border the state of _?

####  4.2.2 StableBeluga-13B prompts:

  1. 1.

### System:\nYou are a helpful, respectful and honest assistant. Your answers
should be crisp, short and not repititive.\nGive valid wikipedia page titles
in the answer. The answer should be in a python list of string format.\nIf you
dont know the answer from both the given context and your past knowledge,
answer should just be a python empty list.\n\n### User:\ncontext:
{context}\n\n{question}\n\n### Assistant\nAnswer: {answer}

  2. 2.

### System:\nYou are a helpful, respectful and honest assistant. Your answers
should be crisp, short and not repititive.\nGive valid wikipedia page titles
in the answer. The answer should be in a python list of string format.\nIf you
dont know the answer from both the given context and your past knowledge,
answer should just be a python empty list.\n\n### User:\ncontext:
”\n\n{question}\n\n### Assistant\nAnswer: {answer}

  3. 3.

### System:\nYou are a helpful, respectful and honest assistant. Your answers
should be crisp, short and not repititive.\nChoose an answer from the options
in the context.\nIf you dont know the answer from both the given context,
answer should just be a python empty list.\n\n### User:\ncontext:
{options}\n\n{question}\n

\n### Assistant\nAnswer: [’{answer}’]

  4. 4.

### System:\n Example 1: Wrong Format: [’People’s Republic of China’, ’Laos’,
’Thailand’, ’India’, ’Bangladesh’]”].

Correct Format: Answer: ”People’s Republic of China”, ”Laos”,

”Thailand”, ”India”, ”Bangladesh”] </s>\n

Example 2: Wrong Format: [’Artibonite’, ’Nord-Est Department’, ’South
Department’,’West Department’, ’Centre Department’,

’Grand’Anse Department’, ’North Department’]. Correct Format: Answer:
”Artibonite”, ”Nord-Est Department”, ”South Department”, ”West Department”,
”Centre Department”, ”Grand’Anse Department”, ”North Department”] </s>\n

Example 3: Wrong Format: [’book’s and page’s’]. Correct Format: Answer:
[”book’s and page’s”]\n\n

### User:\n Your answer should only be a valid python list of string format.
Do not give any explainations.\n\n Use the examples to convert {answer} into a
correct python list.\n\n ###Assistant\nAnswer:

The {question}, {answer}, {context} and {options} variables are generated in
the same method as described for the Llama-2-13b-chat prompts.

###  4.3 Training

For both base models namely Llama-2-13b-chat and StableBeluga-13B, we load
them in 4 bit quantized state with frozen weights and only train an injection
model using LoRA technique. The injection model has $\approx$0.05 % of the
parameters of the base models. The training setup was as follows:

  * •

Libraries: BitsandBytes [28, 29], HuggingFace [30], PyTorch [31]

  * •

Base model: BitsandBytesConfig(load_in_4bit=True,

bnb_4bit_use_double_quant=True,

bnb_4bit_quant_type=”nf4”, bnb_4bit_compute_dtype=torch.bfloat16)

  * •

LoRA model: alpha=16, dropout=0.05, r=4, bias=”none”,

task_type=”CAUSAL_LM”

  * •

Trainer: epochs=3, optimizer=”paged_adamw_32bit”,

gradient_accumulation_steps=2, per_device_train_batch_size=1,

per_device_eval_batch_size= 4, fp16=True,

learning_rate=2e-5, max_grad_norm=0.3, warmup_ratio=0.03,

lr_scheduler_type=”constant”

  * •

GPU: 2x NVIDIA V100

###  4.4 Inference

The overall architecture can be seen in Fig. 1. During inference, we first try
to fetch the English language Wikipedia page text of the subject entity using
its Wikidata ID. If the subject entity does not have an English page, we then
pick the text from the primary alternate language page. We then split the text
into chunks of 300 tokens (with an overlap of 50 tokens to maintain
continuity) due to the following reasons:

  * •

LLM have a limit on the context length, which in the case of Llama-2-13b-chat
and StableBeluga-13B is 4096 tokens. Since the Wikipedia text is usually large
and may cross the maximum context length supported by the LLM, it is not
feasible to consume the entire context in one shot.

  * •

Due to the size of the LLM, passing lengthy inputs increases the inference
time. Further, it makes much more sense to pick those chunks of information
from the entire Wikipedia page that are relevant to a given question.

Each of the context chunks are encoded using the DPR context encoder and
stored in a FAISS vector store for fast search and retrieval. To ensure that
the LLM is not just fixated on using only top 2 contexts, during inference we
pick top 3 contexts to test its robustness towards handling variability. To
pick the top 3 relevant context chunks for a given question, the question is
encoded using the DPR question encoder and then passed to FAISS. The top 3
retrieved context chunks are concatenated to form the {context} variable for
the prompts. In cases where a subject entity does not have a Wikipedia page,
the {context} variable will be empty for the prompt, and the LLM will have to
rely on its stored knowledge to answer the question. Prompt 1 is executed if a
context was found whereas Prompt 2 is executed if no context was found.

Once the LLM processes the prompt, the answer can have 0 or more object
entities. For disambiguating each of these surface strings, we query the
Wikidata API with each of these object entities separately. The API will
return a list of candidate Wikidata entities, from which we attempt to find
the correct disambiguated entity. To do this, we collect all the candidate
entities and put them in a list to form the {context} in Prompt 3. The
expectation is that the LLM picks the correct disambiguated entity relevant to
the question. For e.g. if the question is ”Who is William Shakespeare married
to?”, and the LLM correctly answers ”Anne Hathaway”, Wikidata API will return
entities of both Anne Hathaway (wife of William Shakespeare) and Anne Hathaway
(American actress). With Prompt 3, we believe that providing the question to
the LLM will help us to disambiguate and pick the correct candidate. The
Wikidata ID of each disambiguated object entity is then fetched and stored. In
cases where the LLM generated a string which was not an exact match of the
provided options, we pass the LLM output to Wikipedia API for fetching the
most relevant entity.

Table 2: LLM2KB results (Precision, Recall and F-1 score are macro average per relation) on Test set with Llama-2-13b-chat. Train + Validation set were used to generate training samples. Relation | Precision | Recall | F1 score
---|---|---|---
BandHasMember | 0.7178 | 0.4151 | 0.4857
CityLocatedAtRiver | 0.7400 | 0.5205 | 0.5586
CompanyHasParentOrganisation | 0.7200 | 0.7200 | 0.6400
CompoundHasParts | 0.9318 | 0.8495 | 0.8784
CountryBordersCountry | 0.8492 | 0.5848 | 0.6719
CountryHasOfficialLanguage | 0.9154 | 0.7500 | 0.8015
CountryHasStates | 0.5687 | 0.3872 | 0.4399
FootballerPlaysPosition | 0.7050 | 0.6683 | 0.6783
PersonCauseOfDeath | 0.8500 | 0.8200 | 0.8200
PersonHasAutobiography | 0.6700 | 0.4075 | 0.4173
PersonHasEmployer | 0.5100 | 0.2957 | 0.3327
PersonHasNoblePrize | 0.9900 | 0.9350 | 0.9367
PersonHasNumberOfChildren | 0.4900 | 0.4900 | 0.4900
PersonHasPlaceOfDeath | 0.8300 | 0.7600 | 0.7200
PersonHasProfession | 0.6600 | 0.4628 | 0.5034
PersonHasSpouse | 0.7700 | 0.5850 | 0.5867
PersonPlaysInstrument | 0.7633 | 0.6159 | 0.6354
PersonSpeaksLanguage | 0.8500 | 0.7538 | 0.7704
RiverBasinsCountry | 0.8883 | 0.7689 | 0.7896
SeriesHasNumberOfEpisodes | 0.4500 | 0.4500 | 0.4500
StateBordersState | 0.5090 | 0.3416 | 0.3815
Average | 0.7323 | 0.5991 | 0.6185
Table 3: LLM2KB results (Precision, Recall and F-1 score are macro average per relation) on Test set with Llama-2-13b-chat. Only Train set was used to generate training samples. Relation | Precision | Recall | F1 score
---|---|---|---
BandHasMember | 0.7235 | 0.4132 | 0.4822
CityLocatedAtRiver | 0.7200 | 0.4948 | 0.5291
CompanyHasParentOrganisation | 0.7400 | 0.7550 | 0.6667
CompoundHasParts | 0.9280 | 0.7909 | 0.8442
CountryBordersCountry | 0.8439 | 0.5501 | 0.6442
CountryHasOfficialLanguage | 0.9000 | 0.7372 | 0.7877
CountryHasStates | 0.5602 | 0.3669 | 0.4221
FootballerPlaysPosition | 0.7450 | 0.4900 | 0.4917
PersonCauseOfDeath | 0.8600 | 0.8133 | 0.8150
PersonHasAutobiography | 0.6900 | 0.4125 | 0.4240
PersonHasEmployer | 0.4100 | 0.2237 | 0.2555
PersonHasNoblePrize | 0.9700 | 0.9550 | 0.9567
PersonHasNumberOfChildren | 0.4300 | 0.4300 | 0.4300
PersonHasPlaceOfDeath | 0.8600 | 0.8100 | 0.7800
PersonHasProfession | 0.6050 | 0.4560 | 0.4856
PersonHasSpouse | 0.7600 | 0.5650 | 0.5667
PersonPlaysInstrument | 0.7100 | 0.5982 | 0.6133
PersonSpeaksLanguage | 0.8650 | 0.7327 | 0.7607
RiverBasinsCountry | 0.8925 | 0.7851 | 0.7997
SeriesHasNumberOfEpisodes | 0.4800 | 0.4800 | 0.4800
StateBordersState | 0.5977 | 0.3352 | 0.3983
Average | 0.7281 | 0.5807 | 0.6016
Table 4: LLM2KB results (Precision, Recall and F-1 score are macro average per relation) on Test set with StableBeluga-13B. Train + Validation set were used to generate training samples. Relation | Precision | Recall | F1 score
---|---|---|---
BandHasMember | 0.7075 | 0.4227 | 0.4850
CityLocatedAtRiver | 0.7300 | 0.4865 | 0.5225
CompanyHasParentOrganisation | 0.8800 | 0.6500 | 0.6300
CompoundHasParts | 0.8573 | 0.6581 | 0.7197
CountryBordersCountry | 0.8360 | 0.4690 | 0.5654
CountryHasOfficialLanguage | 0.9462 | 0.7372 | 0.8021
CountryHasStates | 0.7984 | 0.3225 | 0.3853
FootballerPlaysPosition | 0.7100 | 0.4933 | 0.5050
PersonCauseOfDeath | 0.8800 | 0.8000 | 0.8000
PersonHasAutobiography | 0.8100 | 0.3450 | 0.3533
PersonHasEmployer | 0.6700 | 0.2128 | 0.2403
PersonHasNoblePrize | 0.9800 | 0.7700 | 0.7700
PersonHasNumberOfChildren | 0.4400 | 0.4400 | 0.4400
PersonHasPlaceOfDeath | 0.9400 | 0.6700 | 0.6700
PersonHasProfession | 0.6100 | 0.3962 | 0.4457
PersonHasSpouse | 0.8500 | 0.4450 | 0.4467
PersonPlaysInstrument | 0.7667 | 0.5577 | 0.6055
PersonSpeaksLanguage | 0.8850 | 0.6190 | 0.6947
RiverBasinsCountry | 0.9170 | 0.7684 | 0.8030
SeriesHasNumberOfEpisodes | 0.4200 | 0.4200 | 0.4200
StateBordersState | 0.6817 | 0.2269 | 0.2872
Average | 0.7769 | 0.5195 | 0.5520

##  5 Results and Future Work

The relation level performance of our system can be seen in Table 2, Table 3
and Table 4. Our primary experiments involved utilising training samples
generated using method 1 for Llama-2-13b-chat and StableBeluga-13B.
Additionally, we also trained a Llama-2-13b-chat model with method 2 used to
generate training samples. Our best performing model was Llama-2-13b-chat when
trained on instruction samples generated using method 1. In training with both
method 1 and method 2 data generation strategies, Llama-2-13b-chat performed
better than StableBeluga-13B.

’PersonHasNoblePrize’ is the highest scoring relation from our best model and
’PersonHasEmployer’ is the lowest scoring relation from our best model. All
the 3 models did not perform very highly on the 2 relations which only
expected numeric answers namely ’PersonHasNumberOfChildren’ and
’SeriesHasNumberOfEpisodes’ even after supplying context. After going through
the Wikipedia contexts for the subject entities of these relations, we
observed that a large majority of them never mention anything about number of
children or number of episodes, leaving the LLM to solely rely on its memory
of factual knowledge. Overall we observed that the following are some of the
practical challenges after subjective analysis of the results:

  * •

Fragility of LLM during inference towards minor changes in prompts.

  * •

Hallucinations of LLM.

  * •

LLM produces a correct surface string of an object but Wikidata API is unable
to return any relevant entities for it.

Our future work will focus on utilising 30 billion and 70 billion versions of
LLM to see if that can push the performance further and also experiment with
Chain-of-Thought prompt techniques.

## References

  * [1] OpenAI, 2023. GPT-4 Technical Report, 33. arXiv preprint arXiv:2303.08774.
  * [2] Touvron, H., Martin, L., Stone, K., Albert, P., Almahairi, A., Babaei, Y., Bashlykov, N., Batra, S., Bhargava, P., Bhosale, S. and Bikel, D., 2023. Llama 2: Open foundation and fine-tuned chat models. arXiv preprint arXiv:2307.09288.
  * [3] Stability AI Stable Beluga, https://stability.ai/blog/stable-beluga-large-instruction-fine-tuned-models. Last accessed 7 Aug 2023.
  * [4] Hu, E.J., Shen, Y., Wallis, P., Allen-Zhu, Z., Li, Y., Wang, S., Wang, L. and Chen, W., 2021. Lora: Low-rank adaptation of large language models. arXiv preprint arXiv:2106.09685.
  * [5] LM-KBC Homepage, https://lm-kbc.github.io/challenge2023/. Last accessed 7 Aug 2023.
  * [6] Petroni, F., Rocktäschel, T., Riedel, S., Lewis, P., Bakhtin, A., Wu, Y. and Miller, A., 2019, November. Language Models as Knowledge Bases?. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP) (pp. 2463-2473).
  * [7] Razniewskia, S., Yatesa, A., Kassnerc, N. and Weikuma, G., 2021. Language Models As or For Knowledge Bases.
  * [8] Jiang, Z., Xu, F.F., Araki, J. and Neubig, G., 2020. How can we know what language models know?. Transactions of the Association for Computational Linguistics, 8, pp.423-438.
  * [9] Bouraoui, Z., Camacho-Collados, J. and Schockaert, S., 2020, April. Inducing relational knowledge from BERT. In Proceedings of the AAAI Conference on Artificial Intelligence (Vol. 34, No. 05, pp. 7456-7463).
  * [10] Haviv, A., Berant, J. and Globerson, A., 2021, April. BERTese: Learning to Speak to BERT. In Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: Main Volume (pp. 3618-3623).
  * [11] Shin, T., Razeghi, Y., Logan IV, R.L., Wallace, E. and Singh, S., 2020, November. AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 4222-4235).
  * [12] Qin, G. and Eisner, J., 2021, June. Learning How to Ask: Querying LMs with Mixtures of Soft Prompts. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (pp. 5203-5212).
  * [13] Zhong, Z., Friedman, D. and Chen, D., 2021, June. Factual Probing Is [MASK]: Learning vs. Learning to Recall. In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (pp. 5017-5033).
  * [14] Fichtel, L., Kalo, J.C. and Balke, W.T., 2021, June. Prompt tuning or fine-tuning-investigating relational knowledge in pre-trained language models. In 3rd Conference on Automated Knowledge Base Construction.
  * [15] He, T., Cho, K. and Glass, J., 2021. An empirical study on few-shot knowledge probing for pretrained language models. arXiv preprint arXiv:2109.02772.
  * [16] Kalo, J.C., Fichtel, L., Ehler, P. and Balke, W.T., 2020. KnowlyBERT-Hybrid query answering over language models and knowledge graphs. In The Semantic Web–ISWC 2020: 19th International Semantic Web Conference, Athens, Greece, November 2–6, 2020, Proceedings, Part I 19 (pp. 294-310). Springer International Publishing.
  * [17] Arnaout, H., Tran, T.K., Stepanova, D., Gad-Elrab, M.H., Razniewski, S. and Weikum, G., 2022. Utilizing Language Model Probes for Knowledge Graph Repair.
  * [18] Biswas, R., Sofronova, R., Alam, M., Heist, N., Paulheim, H. and Sack, H., 2021. Do judge an entity by its name! entity typing using language models. In The Semantic Web: ESWC 2021 Satellite Events: Virtual Event, June 6–10, 2021, Revised Selected Papers 18 (pp. 65-70). Springer International Publishing.
  * [19] Singhania, S., Nguyen, T.P. and Razniewski, S., 2022. LM-KBC: Knowledge Base Construction from Pre-trained Language Models.
  * [20] Li, T., Huang, W., Papasarantopoulos, N., Vougiouklis, P. and Pan, J.Z., 2022. Task-specific Pre-training and Prompt Decomposition for Knowledge Graph Population with Language Models.
  * [21] Alivanistos, D., Santamaría, S.B., Cochez, M., Kalo, J.C., van Krieken, E. and Thanapalasingam, T., 2022. Prompting as Probing: Using Language Models for Knowledge Base Construction.
  * [22] Brown, T., Mann, B., Ryder, N., Subbiah, M., Kaplan, J.D., Dhariwal, P., Neelakantan, A., Shyam, P., Sastry, G., Askell, A. and Agarwal, S., 2020. Language models are few-shot learners. Advances in neural information processing systems, 33, pp.1877-1901.
  * [23] Ning, X. and Celebi, R., 2022. Knowledge Base Construction from Pre-trained Language Models by Prompt learning.
  * [24] Fang, X., Kalinowski, A., Zhao, H., You, Z., Zhang, Y. and An, Y., 2022. Prompt Design and Answer Processing for Knowledge Base Construction from Pre-trained Language Models (KBC-LM).
  * [25] Dalal, S., Sharma, A., Jain, S. and Dave, M., 2022. Manual Prompt Generation For Language Model Probing.
  * [26] Mukherjee, S., Mitra, A., Jawahar, G., Agarwal, S., Palangi, H. and Awadallah, A., 2023. Orca: Progressive learning from complex explanation traces of gpt-4. arXiv preprint arXiv:2306.02707.
  * [27] Karpukhin, V., Oguz, B., Min, S., Lewis, P., Wu, L., Edunov, S., Chen, D. and Yih, W.T., 2020, November. Dense Passage Retrieval for Open-Domain Question Answering. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP) (pp. 6769-6781).
  * [28] Dettmers, T., Lewis, M., Belkada, Y. and Zettlemoyer, L., 2022. Llm. int8 (): 8-bit matrix multiplication for transformers at scale. arXiv preprint arXiv:2208.07339.
  * [29] Dettmers, T., Lewis, M., Shleifer, S. and Zettlemoyer, L., 2021. 8-bit optimizers via block-wise quantization. arXiv preprint arXiv:2110.02861.
  * [30] Wolf, T., Debut, L., Sanh, V., Chaumond, J., Delangue, C., Moi, A., Cistac, P., Rault, T., Louf, R., Funtowicz, M. and Davison, J., 2019. Huggingface’s transformers: State-of-the-art natural language processing. arXiv preprint arXiv:1910.03771.
  * [31] Paszke, A., Gross, S., Massa, F., Lerer, A., Bradbury, J., Chanan, G., Killeen, T., Lin, Z., Gimelshein, N., Antiga, L. and Desmaison, A., 2019. Pytorch: An imperative style, high-performance deep learning library. Advances in neural information processing systems, 32.


# Hamiltonian formalism for nonlinear Schrödinger equations

Ali Pazarci  Department of Physics, Bogazici University, 34342 Bebek,
Istanbul, Turkey  Umut Can Turhan  Department of Physics, Mimar Sinan Fine
Arts University, Bomonti 34380, Istanbul, Turkey  Nader Ghazanfari  Department
of Physics, Mimar Sinan Fine Arts University, Bomonti 34380, Istanbul, Turkey
Ilmar Gahramanov  Department of Physics, Bogazici University, 34342 Bebek,
Istanbul, Turkey  Department of Mathematics, Khazar University, Mehseti St.
41, AZ1096, Baku, Azerbaijan

###### Abstract

We study the Hamiltonian formalism for second order and fourth order nonlinear
Schrödinger equations. In the case of second order equation, we consider cubic
and logarithmic nonlinearities. Since the Lagrangians generating these
nonlinear equations are degenerate, we follow the Dirac-Bergmann formalism to
construct their corresponding Hamiltonians. In order to obtain consistent
equations of motion, the Dirac-Bergmann formalism imposes some set of
constraints which contribute to the total Hamiltonian along with their
Lagrange multipliers. The order of the Lagrangian degeneracy determines the
number of the primary constraints. Multipliers are determined by the time
consistency of constraints. If a constraint is not a constant of motion, a
secondary constraint is introduced to force the consistency. We show that for
both second order nonlinear Schrödinger equations we only have primary
constraints, and the form of nonlinearity does not change the constraint
dynamics of the system. However, introducing a higher order dispersion changes
the constraint dynamics and secondary constraints are needed to construct a
consistent Hamilton equations of motion.

##  I Introduction

For a regular Lagrangian, the Hamiltonian can be constructed through a
straightforward Legendre transformation. However, in the case of the
degenerate Lagrangians, for which the field variables are not independent and
are connected to each other through some constraints, a new procedure is
needed to construct a Hamiltonian which produces consistent equations of
motion [1]. In the late 40’s and early 50’s Bergmann [2, 3, 4] and Dirac [5,
6, 7] independently developed a Hamilton formalism for these degenerate
Lagrangians, which are equivalently called singular Lagrangian systems or
constrained Hamilton systems. The algorithm initially introduces a set of
constraints, usually called primary constraints, with corresponding Lagrange
multipliers to be determined. However, the dynamics of these constraints may
also introduce the so-called secondary constraints. Such construction is
important for the quantization of gauge theories in the functional integral
formalism, furthermore, the constraint analysis can be used to handle higher
derivative Lagrangian theories [8].

Here, we study the Hamiltonian formalism of the nonlinear Schrödinger
equations (NLSEs). These equations have degenerate Lagrangians.
Mathematically, a Lagrangian is called degenerate if the determinant of the
Hessian matrix is zero [1]. Since there are constraints in the NLSEs caused by
the singularity of the Hessian matrix, therefore, we use the Dirac-Bergmann
algorithm (DBA) for constructing the consistent Hamiltonians.

NLSEs are classical field equations and are widely used to describe the
properties of different physical systems. In nonlinear optics, the propagation
of light in fibers and waveguides with nonlinear effects are governed by both
second order and higher order NLSEs [9, 10, 11]. The higher order dispersions
become considerable when the pulses become extremely short [12]. Moreover, The
Gross-Pitaevskii equation, which is a second order NLSE, describes the general
properties of trapped Bose–Einstein condensates [13, 14]. Solutions of these
equations are studied in detail in the context of optics and condensed matter
physics. The soliton solutions of these equations are widely investigated
[15], and their instabilities due to the competition between dispersion and
nonlinearity are well-known [16, 17].

This article is organized as follows. We first describe the DBA used to
construct consistent Hamilton equations of motion from a degenerate
Lagrangian. Then, we apply the DBA to second order NLSEs. We show that the
Hamilton equations of motion for these systems can be constructed only by
introducing primary constraints. By analyzing the already studied the
Korteweg-de Vries equation, we show that the higher order dispersions in the
equation of motion generates secondary constraints. Eventually, we study the
constraint dynamics of fourth order NLSE. Due to the higher order dispersion,
we observe the need for secondary constraints as well.

##  II Dirac-Bergmann algorithm

The DBA is a set of well-defined rules to construct the Hamiltonian from a
degenerate Lagrangian [1]. For a field $\psi(\textbf{r},t)$ a Lagrangian

$L=\int
d\textbf{r}\,\mathcal{L}\left[\psi_{i},\nabla\psi_{i},\left(\psi_{i}\right)_{t}\right]$
(1)

is called degenerate if the determinant of the Hessian matrix of the
Lagrangian density $\mathcal{L}$ becomes zero, i.e.

$\left|\frac{\delta^{2}\mathcal{L}}{\delta({\psi_{i}})_{t}\delta({\psi_{j}})_{t}}\right|=0\,.$
(2)

Here, $\psi_{t}$ denotes the time derivative of the field
$\psi(\textbf{r},t)$. Naturally, a Lagrangian is regular if the Hessian does
not vanish. It may be seen from a Lagrangian density that a linear dependency
on the total time derivatives of all fields corresponds to a degenerate
Lagrangian density. The DBA introduces an initial set of primary constraints
depending on the order of the degeneracy in the system. However, the dynamics
of these constraints may also introduce a set of secondary constraints. These
constraints with their corresponding multipliers contribute to the total
Hamiltonian. Here, we follow the DBA step by step and construct a Hamiltonian
which generates the consistent set of equations of motion.

After confirming the degeneracy of the Lagrangian, the number of the primary
constraints are determined from the difference between dimension and rank of
the Hessian matrix [18, 19]. These primary constraints are naturally chosen to
be the canonical momenta definitions, i.e.

$\pi_{\psi_{i}}=\frac{\delta\mathcal{L}}{\delta(\psi_{i})_{t}}.$ (3)

Each primary constraint $c_{i}$ contributes to the total Hamiltonian with its
corresponding Lagrange multiplier $\lambda_{i}$. With the additional
contribution of constraint $\mathcal{H}_{c}=\sum_{i}\lambda_{i}c_{i}$, the
total Hamiltonian can be written as

$\displaystyle H=\int
d\textbf{r}\,\left(\mathcal{H}_{L}+\mathcal{H}_{c}\right),$ (4)

where $\mathcal{H}_{L}=\sum_{i}\pi_{\psi_{i}}(\psi_{i})_{t}-\mathcal{L}$ is
the canonical Hamiltonian density.

The next step in the DBA is to determine the multipliers $\lambda_{i}$.
Consistent equations of motion can be constructed from these constraints only
if they are constant of motion, in the other words, the Poisson bracket of the
constraint with the total Hamiltonian is zero, i.e. $\\{c_{i},H\\}=0$ .
Practically, if this Poisson bracket contains any multiplier, the result can
be set to zero. Accordingly, a set of vanishing Poisson bracket will give a
set of linear equations for certain multipliers, which can be solved to obtain
those multipliers. However, if a constraint is not a constant of motion, in
other words, the Poisson bracket of the constraint with the total Hamiltonian
does not contain any multiplier, the result should be forced to vanish which
generates a new constraint, namely, the secondary constraint $\tilde{c}_{i}$.
Secondary constraints are not distinct in nature from primary constraints, and
their contribution to the total Hamiltonian is determined similarly, but with
a new set of Lagrange multipliers $\tilde{\lambda}_{i}$. Thus, the new
constraint Hamiltonian density can be written as

$\mathcal{H}_{c}=\sum_{i}\left(\lambda_{i}c_{i}+\tilde{\lambda}_{i}\tilde{c}_{i}\right).$
(5)

If the consistency conditions for the new set of constraints,
$\\{\tilde{c}_{i},H\\}=0$, are not established a new set of constraints,
namely tertiary constraints, are defined and their contributions are added to
$\mathcal{H}_{c}$ accordingly. This procedure will be maintained until all the
multipliers are determined. Then, we have the total Hamiltonian $H$ after the
substitution of multipliers.

Throughout this procedure, to construct a Hamiltonian with consistent
equations of motion, we have altered the total Hamiltonian by utilizing
constraints. Instead, one may alter the structure of the Poisson bracket
equivalently and define Dirac brackets. However, in this manuscript, for the
sake of simplicity and better understanding the main DBA we are not going to
the details of this procedure. In order to get a close insight into the DBA,
in the following sections, we apply this procedure to different Lagrangians
and construct their corresponding Hamiltonians.

##  III Nonlinear Schrödinger Equation

Nonlinear Schrödinger equations are classical field equations and are widely
used to describe the properties of the different physical systems from the
propagation of light in nonlinear optics [9, 10] to trapped Bose–Einstein
condensates [13, 14]. In this section, we will construct a Lagrangian for each
of the two mostly used different equations of motion, generally called the
cubic and the logarithmic nonlinear Schrödinger equations.

###  III.1 Cubic nonlinear Schrödinger

The cubic nonlinear Schrödinger equation

$iu_{t}+u_{xx}+2|u|^{2}u=0$ (6)

is one of the most studied nonlinear equations in physics [13, 14, 10]. Here,
$u_{t}$ and $u_{xx}$ are first order time and second order spatial derivative
of a classical field $u(x,t)$. This equation is completely integrable as a
Hamiltonian system, it was solved exactly by the method of the inverse
scattering by Zakharov and Shabat [20] (see also [21, 15]). First, we
construct a Lagrangian that gives the nonlinear Schrödinger equation as an
equation of motion. Since the expression (6) contains an imaginary part, one
needs a Lagrangian with complex terms. Note that the Hamilton’s equations and
corresponding Poisson brackets for the nonlinear Schrödinger equation are
written in the complex form in integrability literature, see, e.g. [21]. Here,
we are interested in the construction of a real valued Lagrangian system,
therefore, we factorize the nonlinear Schrödinger equation to imaginary and
real parts by setting $u(x,t)=\phi(x,t)e^{i\theta(x,t)}$ which leads us to two
equations of motion

$\displaystyle\phi_{t}$ $\displaystyle=-\theta_{xx}\phi-2\phi_{x}\theta_{x},$
(7) $\displaystyle\phi\theta_{t}$
$\displaystyle=2\phi^{3}+\phi_{xx}-\phi\theta_{x}^{2}\;.$

The Lagrangian density whose variations with respect to $\phi$ and $\theta$
determine the $\phi_{t}$ and $\theta_{t}$ in accordance with (7) has the
following form

$L_{nls}=\int dx\,\mathcal{L}_{nls}=\int
dx\left(-\frac{1}{2}\theta_{t}\phi^{2}+\frac{1}{2}\phi^{4}-\frac{1}{2}\phi_{x}^{2}-\frac{1}{2}\theta_{x}^{2}\phi^{2}\right).$
(8)

Since the determinant of the Hessian matrix for this Lagrangian is zero, i.e.,

$\det\begin{bmatrix}\frac{\partial^{2}\mathcal{L}}{\partial\phi_{t}\partial\phi_{t}}&\frac{\partial^{2}\mathcal{L}}{\partial\phi_{t}\partial\theta_{t}}\\\
\\\
\frac{\partial^{2}\mathcal{L}}{\partial\theta_{t}\partial\phi_{t}}&\frac{\partial^{2}\mathcal{L}}{\partial\theta_{t}\partial\theta_{t}}\;.\end{bmatrix}=0,$
(9)

the Lagrangian is degenerate. The Hessian matrix has a rank of zero, so that
the difference between the dimensionality of the matrix and its rank imposes
two primary constraints. As we mentioned in the previous section, the
corresponding equations for canonical momenta of fields $\theta$ and $\phi$

$\pi_{\phi}=0,\>\>\>\>\>\>\>\>\pi_{\theta}=-\frac{1}{2}\phi^{2},\;$ (10)

are natural choices for the two needed primary constraints. Therefore, we set
two primary constraints as

$c_{1}=\pi_{\phi},\>\>\>\>\>\>\>\>c_{2}=\pi_{\theta}+\frac{1}{2}\phi^{2}.$
(11)

By adding the contribution of the constraints $\mathcal{H}_{c}$ to the
canonical $\mathcal{H}_{L}$, we can construct the total Hamiltonian density as
follows,

$\displaystyle\mathcal{H}_{nls}$
$\displaystyle=\mathcal{H}_{L}+\mathcal{H}_{c}$
$\displaystyle=\pi_{\theta}\theta_{t}+\pi_{\phi}\phi_{t}-\mathcal{L}_{nls}+\lambda_{1}c_{1}+\lambda_{2}c_{2}.$
(12)

After the substitution of the canonical momenta and the constraints, we have

$\mathcal{H}_{nls}=-\frac{1}{2}\phi^{4}+\frac{1}{2}\phi_{x}^{2}+\frac{1}{2}\theta_{x}^{2}\phi^{2}+\lambda_{1}\pi_{\phi}+\lambda_{2}\left(\pi_{\theta}+\frac{1}{2}\phi^{2}\right).$
(13)

In order to determine the multipliers $\lambda_{1}$ and $\lambda_{2}$, we
check the so-called consistency conditions, which basically determines the
preservation of the constraints under time variation. These consistency
conditions, established by the Poisson brackets of the constraints with the
total Hamiltonian, $H_{nls}=\int dx\,\mathcal{H}_{nls}$,

$\displaystyle\\{c_{1},H_{nls}\\}$
$\displaystyle=2\phi^{3}+\phi_{xx}-\phi\theta_{x}^{2}-\lambda_{2}\phi,$ (14)
$\displaystyle\\{c_{2},H_{nls}\\}$
$\displaystyle=\lambda_{1}\phi+\phi^{2}\theta_{xx}+2\phi\phi_{x}\theta_{x},$

lead us to the determination of the multipliers $\lambda_{1}$ and
$\lambda_{2}$,

$\displaystyle\lambda_{1}$
$\displaystyle=-\theta_{xx}\phi-2\phi_{x}\theta_{x},$ (15)
$\displaystyle\lambda_{2}$
$\displaystyle=2\phi^{2}-\theta_{x}^{2}+\frac{\phi_{xx}}{\phi}.$

By substituting the determined multipliers into the total Hamiltonian density
and doing the necessary cancellations, we obtain

$\mathcal{H}_{nls}=\frac{1}{2}\phi^{4}+\pi_{\phi}\left(-\phi\theta_{xx}-2\phi_{x}\theta_{x}\right)+\pi_{\theta}\left(2\phi^{2}-\theta_{x}^{2}+\frac{\phi_{xx}}{\phi}\right).$
(16)

Now, we can calculate the equations of motion from the total Hamiltonian.

$\displaystyle\phi_{t}=-\theta_{xx}\phi-2\phi_{x}\theta_{x},$ (17a)
$\displaystyle\phi\theta_{t}=2\phi^{3}+\phi_{xx}-\phi\theta_{x}^{2},$ (17b)
$\displaystyle\left(\pi_{\phi}\right)_{t}=0,$ (17c)
$\displaystyle\left(\pi_{\theta}\right)_{t}=2\phi\phi_{x}\theta_{x}+\phi^{2}\theta_{xx}.$
(17d)

The first two equations (17a) and (17b) are the same as the equations of
motion (7), from which we constructed the Lagrangian (8). If we substitute the
canonical momenta into the total Hamiltonian with the integrand (16), and
perform an integration by parts, we obtain

$H_{nls}=\int
dx\,\left(\frac{1}{2}\phi_{x}^{2}+\frac{1}{2}\phi^{2}\theta_{x}^{2}-\frac{1}{2}\phi^{4}\right),$
(18)

which is a redefined version of

$H_{nls}=\int
dx\,\left(\frac{1}{2}|\psi_{x}|^{2}-\frac{1}{2}|\psi|^{4}\right),$ (19)

with $\psi=\phi e^{i\theta}$. The expression (19) is used in integrability
community as the Hamiltonian of the nonlinear Schrodinger equation.

###  III.2 Logarithmic nonlinear Schrödinger equation

For the Logarithmic nonlinear Schrödinger equation [22]

$iu_{t}+u_{xx}+u\ln{|u|^{2}}=0,$ (20)

similar to the cubic nonlinear Schrödinger equation, to obtain a real valued
Lagrangian we set $u(x,t)=\phi(x,t)e^{i\theta(x,t)}$, which leads us to two
equations of motion

$\displaystyle\phi_{t}$ $\displaystyle=-2\phi_{x}\theta_{x}-\phi\theta_{xx}$
(21) $\displaystyle\phi\theta_{t}$
$\displaystyle=\phi_{xx}-\phi\theta_{x}^{2}+2\phi\ln\phi.$

From these equations of motions, we construct the logarithmic Lagrangian
density

$\mathcal{L}_{lnls}=-\frac{1}{2}\phi^{2}\theta_{t}-\frac{1}{2}\phi_{x}^{2}-\frac{1}{2}\phi^{2}\theta_{x}^{2}+\phi^{2}\ln{\phi}-\frac{1}{2}\phi^{2}.$
(22)

By being degenerate, having a rank zero Hessian matrix and giving the same
canonical momenta (10), qualitatively, this logarithmic Lagrangian density is
similar to the cubic one (8). Therefore, we choose the same primary
constraints (11) and write the total Hamiltonian as follows.

$\mathcal{H}_{lnls}=\frac{1}{2}\phi_{x}^{2}+\frac{1}{2}\phi^{2}\theta_{x}^{2}+\frac{1}{2}\phi^{2}-\phi^{2}\ln{\phi}+\lambda_{1}\pi_{\phi}+\lambda_{2}\left(\pi_{\theta}+\frac{1}{2}\phi^{2}\right).$
(23)

Similarly, the two consistency conditions, defined by the Poisson brackets of
the primary constraints with the total Hamiltonian, can determine the
multipliers $\lambda_{1}$ and $\lambda_{2}$. After the substitution of the
multipliers, the total Hamiltonian density can be written as

$\mathcal{H}_{lnls}=\frac{1}{2}\phi^{2}+\pi_{\phi}\left(-\phi\theta_{xx}-2\phi_{x}\theta_{x}\right)+\pi_{\theta}\left(\frac{\phi_{xx}}{\phi}-\theta_{x}^{2}+2\ln{\phi}\right).$
(24)

And eventually, the equations of motion can be obtained as

$\displaystyle\phi_{t}=-2\phi_{x}\theta_{x}-\phi\theta_{xx},$ (25a)
$\displaystyle\phi\theta_{t}=\phi_{xx}-\phi\theta_{x}^{2}+2\phi\ln\phi,$ (25b)
$\displaystyle(\pi_{\phi})_{t}=0,$ (25c)
$\displaystyle(\pi_{\theta})_{t}=2\phi\phi_{x}\theta_{x}+\phi^{2}\theta_{xx}.$
(25d)

We observe that changing the form of the nonlinearity in a degenerate
Lagrangian does not generate a different constraint dynamics, since its
dynamics is set by the order and form of time and spatial derivatives. This
result is best manifested by constraint dynamics of the Korteweg-de Vries
(KdV) and the fourth order nonlinear Schrödinger equations. For both of these
equations of motions, secondary constraints are needed to construct the
Hamiltonian from a degenerate Lagrangian.

##  IV Korteweg-de Vries equation

The KdV equation

$u_{t}-6uu_{x}+u_{xxx}=0,$ (26)

is a useful example of a degenerate Lagrangian for which we need some
secondary constraints to construct the Hamiltonian. Since studying this
example helps to understand the constraint dynamics of fourth order NLSE, we
briefly review the Hamiltonian formalism of this system. The constraint
dynamics of the KdV equation has already been studied in [23] (see also [24,
25]). The Lagrangian density for this equation can be written as

$\mathcal{L}_{KdV}=\frac{1}{2}\phi_{t}\phi_{x}+\phi_{x}^{3}+\phi_{x}\psi_{x}+\frac{1}{2}\psi_{x},$
(27)

where $u(x,t)=\phi_{x}(x,t)$.

Here, an extra field $\psi(x,t)=\phi_{xx}(x,t)$ is introduced to avoid higher
order derivatives in the Lagrangian. Although there are procedures handling
the higher order degenerate Lagrangians, introducing this extra field eases
the Hamiltonian formalism of the original higher order Lagrangian. The
variations of this Lagrangian density (27) with respect to $\phi$ and $\psi$
give two equations of motion as follows.

$\displaystyle\phi_{xt}+6\phi_{x}\phi_{xx}+\psi_{xx}=0,$ (28)
$\displaystyle\psi-\phi_{xx}=0.$

The second equation here gives the extra defined field. Similar to the
previous examples, the rank of the Hessian matrix is zero, and its difference
from the dimension of the Hessian matrix imposes two primary constraints which
can be chosen to be the equations for canonical momenta

$\displaystyle c_{1}$ $\displaystyle=\pi_{\psi},$ (29) $\displaystyle c_{2}$
$\displaystyle=\pi_{\phi}-\frac{1}{2}\phi_{x}.$ (30)

The total Hamiltonian constructed by these primary constraints is

$\mathcal{H}=-\phi_{x}^{3}-\phi_{x}\psi_{x}-\frac{1}{2}\psi^{2}+\lambda_{1}c_{1}+\lambda_{2}c_{2}.$
(31)

Despite all similarities between the Hessian matrix properties of KdV
Lagrangian and each of nonlinear Schrödinger Lagrangians, (8) and (22), the
consistency condition of the constraint $c_{1}$ does not contain any
multiplier, which means we cannot obtain an expression for any multiplier.
Thus, we should force the constraint to be a constant of motion. Explicitly
speaking, the Poisson bracket of the constraint $c_{1}$ and the total
Hamiltonian

$\\{c_{1},H\\}=\psi-\phi_{xx}$ (32)

should be set to zero. Therefore, we need to add the secondary constraint
$\tilde{c}_{3}=\psi-\phi_{xx}$, along with its corresponding multiplier
$\tilde{\lambda}_{1}$ to the total Hamiltonian density

$\mathcal{H}_{KdV}=-\phi_{x}^{3}-\phi_{x}\psi_{x}-\frac{1}{2}\psi^{2}+\lambda_{1}c_{1}+\lambda_{2}c_{2}+\tilde{\lambda}_{3}\tilde{c}_{3}.$
(33)

The secondary constraint here is the result of higher order derivative of the
field $u$. Computations of the consistency conditions lead us to the full
determination of the multipliers, so that the total Hamiltonian can be written
as

$\mathcal{H}_{KdV}=-\phi_{x}^{3}-\phi_{x}\psi_{x}-\frac{1}{2}\psi^{2}+\pi_{\psi}(-\phi_{5x}-6\phi_{x}\phi_{xxx}-6\phi_{xx}^{2})+(\pi_{\phi}-\frac{1}{2}\phi_{x})(-\phi_{3x}-3\phi_{x}^{2})+(\psi-\phi_{xx})^{2}.$
(34)

With a bit of extra calculations, the final form of the total Hamiltonian can
be obtained.

$\mathcal{H}=\frac{1}{2}\phi_{x}^{3}+\frac{1}{2}\psi^{2}+\phi_{x}\psi_{x}+\frac{1}{2}\phi_{xx}^{2}-\pi_{\phi}\left(\phi_{3x}+3\phi_{x}^{2}\right)-\pi_{\psi}\left(\phi_{5x}+6\phi_{xx}^{2}+6\phi_{x}\phi_{3x}\right).$
(35)

Eventually, the equations of motion are obtained as follows,

$\displaystyle\phi_{t}+3\phi_{x}^{2}+\phi_{3x}=0,$ (36a)
$\displaystyle\phi_{xt}+6\phi_{x}\phi_{xx}+\phi_{4x}=0,$ (36b)
$\displaystyle\psi_{t}+6\phi_{xx}^{2}+6\phi_{x}\phi_{3x}+\phi_{5x}=0,$ (36c)
$\displaystyle\psi-\phi_{xx}=0.$ (36d)

Here, the second equation is the spatial derivative of the first equation,
which is consistent with the third equation through the substitution of the
fourth equation.

From the constraint dynamics of the KdV equation, the construction of a
Hamiltonian from a degenerate Lagrangian with secondary constraints can be
followed easily. However, it is not always the case for all systems with
higher order dispersion relation.

##  V Fourth-order nonlinear Schrödinger equation

The fourth order nonlinear Schrödinger equation

$iu_{t}+u_{xx}+u_{4x}+2|u|^{2}u=0.$ (37)

describes the propagation of ultrashort pulses in nonlinear optics [12]. As it
was the case for second order NLSEs, to write a real valued Lagrangian for
this equation, we set $u(x,t)=\phi(x,t)e^{i\theta(x,t)}$, which leads us to
the following equations of motion.

$\displaystyle\phi_{t}=-2\theta_{x}\phi_{x}+4\theta_{x}^{3}\phi_{x}-\phi\theta_{xx}+6\phi\theta_{x}^{2}\theta_{xx}-6\theta_{xx}\phi_{xx}-4\phi_{x}\theta_{3x}-4\theta_{x}\phi_{3x}-\phi\theta_{4x},$
(38)
$\displaystyle\phi\theta_{t}=2\phi^{3}-\phi\theta_{x}^{2}+\phi\theta_{x}^{4}-12\phi_{x}\theta_{x}\theta_{xx}-3\phi\theta_{xx}^{2}+\phi_{xx}-6\phi_{xx}\theta_{x}^{2}-4\phi\theta_{x}\theta_{3x}+\phi_{4x}.$

We write down a Lagrangian density

$\mathcal{L}_{fnls}=-\frac{1}{2}\theta_{t}\phi^{2}+\frac{1}{2}\phi^{4}-\frac{1}{2}\phi_{x}^{2}-\frac{1}{2}\theta_{x}^{2}\phi^{2}+\frac{1}{2}\phi^{2}\theta_{x}^{4}+3\theta_{x}^{2}\phi_{x}^{2}-2\phi^{2}\theta_{x}\theta_{3x}-\frac{3}{2}\phi^{2}\theta_{xx}^{2}+\frac{1}{2}\phi_{xx}^{2},$
(39)

whose variation with respect to $\phi$ and $\theta$ leads us to the equations
of motion given by (38). We introduce two new fields $\xi=\phi_{x}$ and
$\gamma=\theta_{xx}$ to lower the third and fourth order derivatives in the
Lagrangian density. Accordingly, the Lagrangian density can be written as

$\mathcal{L}_{fnls}=-\frac{1}{2}\theta_{t}\phi^{2}+\frac{1}{2}\phi^{4}-\frac{1}{2}\xi^{2}-\frac{1}{2}\theta_{x}^{2}\phi^{2}+\frac{1}{2}\phi^{2}\theta_{x}^{4}+3\theta_{x}^{2}\xi^{2}-2\phi^{2}\theta_{x}\gamma_{x}-\frac{3}{2}\phi^{2}\gamma^{2}+\frac{1}{2}\xi_{x}^{2}.$
(40)

The rank of the Hessian matrix generated from this degenerate Lagrangian
density is again zero. Thus, we need four primary constraints. We set the
equations for the canonical momenta as primary constraints, such that

$c_{1}=\pi_{\phi},\;\;\;\;c_{2}=\pi_{\theta}+\frac{1}{2}\phi^{2},\;\;\;\;c_{3}=\pi_{\xi},\;\;\;\;c_{4}=\pi_{\gamma}.$
(41)

By adding the contribution of the primary constraints, the total Hamiltonian
for this case becomes

$\displaystyle\mathcal{H}_{fnls}$
$\displaystyle=-\frac{1}{2}\phi^{4}+\frac{1}{2}\xi^{2}+\frac{1}{2}\theta_{x}^{2}\phi^{2}-\frac{1}{2}\phi^{2}\theta_{x}^{4}-3\theta_{x}^{2}\xi^{2}-\frac{1}{2}\xi_{x}^{2}+\frac{3}{2}\phi^{2}\gamma^{2}$
$\displaystyle\quad+2\phi^{2}\theta_{x}\gamma_{x}+\lambda_{1}\pi_{\phi}+\lambda_{2}\left(\pi_{\theta}+\frac{1}{2}\phi^{2}\right)+\lambda_{3}\pi_{\xi}+\lambda_{4}\pi_{\gamma}.$
(42)

Following the DBA, we check the consistency conditions to cope with the
uncertainty in the Hamilton equations. The Poisson bracket of the constraints
$c_{1}$ and $c_{2}$ with the total Hamiltonian $H_{fnls}=\int
dx\,\mathcal{H}_{fnls}$ give $\lambda_{2}$ and $\lambda_{1}$, respectively.
However, since the consistency equations for the constraints $c_{3}$ and
$c_{4}$ do not contain any multiplier,

$\displaystyle\\{c_{3},H_{fnls}\\}=6\theta_{x}^{2}\xi-\xi-\xi_{xx}=\tilde{c}_{1},$
(43)
$\displaystyle\\{c_{4},H_{fnls}\\}=2\phi\theta_{xx}+4\phi_{x}\theta_{x}-3\phi\gamma=\tilde{c}_{2},$

we cannot obtain $\lambda_{3}$ or $\lambda_{4}$. Therefore, we introduce them
as secondary constraints and add them into total Hamiltonian with multipliers
$\tilde{\lambda}_{1}$ and $\tilde{\lambda}_{2}$,

$\displaystyle\mathcal{H}_{fnls}$
$\displaystyle=-\frac{1}{2}\phi^{4}+\frac{1}{2}\xi^{2}+\frac{1}{2}\theta_{x}^{2}\phi^{2}-\frac{1}{2}\phi^{2}\theta_{x}^{4}-3\theta_{x}^{2}\xi^{2}-\frac{1}{2}\xi_{x}^{2}+\frac{3}{2}\phi^{2}\gamma^{2}$
$\displaystyle\quad+2\phi^{2}\theta_{x}\gamma_{x}+\lambda_{1}\pi_{\phi}+\lambda_{2}\left(\pi_{\theta}+\frac{1}{2}\phi^{2}\right)+\lambda_{3}\pi_{\xi}+\lambda_{4}\pi_{\gamma}$
$\displaystyle\quad+\tilde{\lambda}_{1}\left(6\theta_{x}^{2}\xi-\xi-\xi_{xx}\right)+\tilde{\lambda}_{2}\left(2\phi\theta_{xx}+4\phi_{x}\theta_{x}-3\phi\gamma\right).$
(44)

Since there are no tertiary constraints for (39), one may solve for all the
multipliers from consistency conditions. We skip the further calculations for
determining the Lagrange multipliers and generating the equations of motions
because of their long expressions. However, they can be obtained
straightforwardly similar to the case of the KdV equation.

##  VI Conclusion

The Dirac-Bergmann algorithm is used to construct the Hamiltonian from a
degenerate Lagrangians. The algorithm introduces a set of constraints and
their corresponding Lagrange multipliers in order to obtain consistent
Hamilton equations of motion. By studying different degenerate Lagrangians, we
conclude that, for nonlinear equations, the form of nonlinearity does not
change the dynamics of the constraints. However, the change of the order in
the spatial derivative of the dispersion term dramatically changes the
constraint dynamics.

## References

  * Sundermeyer [1982] K. Sundermeyer,  _Constrained dynamics with applications to Yang-Mills theory, general relativity, classical spin, dual string model_ (Springer-Verlag, 1982).
  * Bergmann [1949] P. G. Bergmann, Non-linear field theories, Phys. Rev. 75, 680 (1949).
  * Bergmann and Brunings [1949] P. G. Bergmann and J. H. M. Brunings, Non-linear field theories ii. canonical equations and quantization, Rev. Mod. Phys. 21, 480 (1949).
  * Bergmann  _et al._ [1950] P. G. Bergmann, R. Penfield, R. Schiller, and H. Zatzkis, The hamiltonian of the general theory of relativity with electromagnetic field, Phys. Rev. 80, 81 (1950).
  * Dirac [1950] P. A. M. Dirac, Generalized hamiltonian dynamics, Canadian Journal of Mathematics 2, 129–148 (1950).
  * Dirac [1951] P. A. M. Dirac, The hamiltonian form of field dynamics, Canadian Journal of Mathematics 3, 1–23 (1951).
  * Anderson and Bergmann [1951] J. L. Anderson and P. G. Bergmann, Constraints in covariant field theories, Phys. Rev. 83, 1018 (1951).
  * Gitman and Tyutin [2012] D. Gitman and I. V. Tyutin,  _Quantization of fields with constraints_ (Springer Science & Business Media, 2012).
  * Scott [2004] A. Scott,  _Encyclopedia of Nonlinear Science_ (Taylor & Francis Inc, 2004).
  * Powers and Haus [2017] P. Powers and J. Haus,  _Fundamentals of Nonlinear Optics (2nd ed.)_ (CRC Press, 2017).
  * Bialynicki-Birula and Mycielski [1976a] I. Bialynicki-Birula and J. Mycielski, Nonlinear wave mechanics, Annals of Physics 100, 62 (1976a).
  * Hosseini  _et al._ [2018] K. Hosseini, F. Samadani, D. Kumar, and M. Faridi, New optical solitons of cubic-quartic nonlinear schrödinger equation, Optik 157, 1101 (2018).
  * Pethick and Smith [2008] C. J. Pethick and H. Smith,  _Bose–Einstein Condensation in Dilute Gases_, 2nd ed. (Cambridge University Press, 2008).
  * Pitaevskii and Stringari [2016] L. Pitaevskii and S. Stringari,  _Bose-Einstein Condensation and Superfluidity_ (Oxford University Press, 2016).
  * Novikov  _et al._ [1984] S. Novikov, S. V. Manakov, L. P. Pitaevskii, and V. E. Zakharov,  _Theory of solitons: the inverse scattering method_ (Springer Science & Business Media, 1984).
  * Karpman [1994] V. Karpman, Solitons of the fourth order nonlinear schrödinger equation, Physics Letters A 193, 355 (1994).
  * Karpman [1996] V. I. Karpman, Stabilization of soliton instabilities by higher-order dispersion: Fourth-order nonlinear schrödinger-type equations, Phys. Rev. E 53, R1336 (1996).
  * Deriglazov [2010] A. A. Deriglazov,  _Classical mechanics, Hamiltonian and Lagrangian formalism_ (Springer, 2010).
  * Lusanna [2018] L. Lusanna, Dirac–bergmann constraints in physics: Singular lagrangians, hamiltonian constraints and the second noether theorem, International Journal of Geometric Methods in Modern Physics 15, 1830004 (2018).
  * Shabat and Zakharov [1972] A. Shabat and V. Zakharov, Exact theory of two-dimensional self-focusing and one-dimensional self-modulation of waves in nonlinear media, Sov. Phys. JETP 34, 62 (1972).
  * Zakharov and Manakov [1974] V. E. Zakharov and S. V. Manakov, On complete integrability of the nonlinear schroedinger equation, Teor. Mat. Fiz. 19, 332 (1974).
  * Bialynicki-Birula and Mycielski [1976b] I. Bialynicki-Birula and J. Mycielski, Nonlinear Wave Mechanics, Annals Phys. 100, 62 (1976b).
  * Nutku [1984] Y. Nutku, Hamiltonian formulation of the kdv equation, Journal of Mathematical Physics 25, 2007 (1984).
  * Nutku [2000] Y. Nutku, Lagrangian approach to integrable systems yields new symplectic structures for KdV, in  _NATO Advanced Research Workshop on Integrable Hierarchies and Modern Physical Theories (NATO ARW - UIC 2000)_ (2000) arXiv:hep-th/0011052 .
  * Nutku and Pavlov [2002] Y. Nutku and M. Pavlov, Multi-lagrangians for integrable systems, Journal of Mathematical Physics 43, 1441 (2002).