There are currently two major competing algorithms, BERT and GPT. They work in much the same way.
First of all, you need to assemble a substantial corpus of text, then let the AI hide words in certain paragraphs. It will then try to predict the missing words and compare its result with the original text.
This step enables the AI to make connections between each word and associate weights with them.
Giving artificial intelligences the ability to understand human beings is a fully-fledged field of computer science known as natural language processing. The discipline is as old as the Turing test.