How KNN Algorithm Works
What’ is KNN Algorithm
By the definition, we know that the KNN algorithm does not have a training process
What is Phantom type in OCaml
Syntax
The left side of =
represents type, while the right side represents the value.
Reading Notes: In-Context Retrieval-Augmented Language Models
The idea
In-Context RALM1 is the RAG technology for Autoregressive LM. In summary, the RAG technology involves using a retriever during model inference to fetch relevant documents, which are then concatenated with the origin input.
In the In-Context Learning setting, some examples are placed before the user’s input, and then they are fed to LLM. Similarly, the In-Context RALM works in a similar way: it directly concatenates the most relevant retrieved document in front of the model’s input. The advantage is that there’s no need to retrain the LLM. A diagram created with Mermaid is shown below.
Reading Notes: REALM: Retrieval-Augmented Language Model Pre-Training
Introduction
Recently I was planning to learn the RAG technology so I started to read some related papers. I found a good Roadmap in the ACL 2023 Tutorial’s slide. Today’s topic is the most fundamental one: Retrieval-Augmented Language Model Pre-Training (REALM).
The REALM framework uses the Masked LM (BERT) rather than LLM. So I assume that you have a basic understanding of BERT such as how to do pre-train/fine-tuning.
Use Polymorphic Variant Type in Ocaml
Intro
I have been learning and using OCaml for a while. However, I’m still quite confused about the Polymorphic variant feature. Recently, while exploring the Yojson library, I came across this feature again. After some research, I couldn’t find any comprehensive articles about polymorphic variants (the official introduction is not easy to grasp this feature IMHO), only a few related answers12. So I decided to write an article, hoping it will be helpful to you :)
Why Applicative Functor
My workflows of using vim-fugitive in Neovim
Intro
Recently, while using Git with Neovim, I noticed that my workflow isn’t as smooth as I’d like it to be. I tend to exit Neovim, and then type git commands in the terminal. Before committing code changes, I usually check the diff information using delta. To cut down the number of keystrokes, I’ve also enabled the Oh My Zsh’s git
plugin, so I can use a bunch of shortcuts like ga = git add
and gcmsg = git commit -m
Tree-sitter and its Query
Intro
Tree-sitter is a parser generator, that is, we can leverage it to generate a specific parser. In addition to that, it also offers other functionality. For example, we can write a Query using S-expression, which will do the pattern matching on the AST. Before we delve into this feature, let’s talk about some backgrounds
S-expression
We can define a S-expression recursively, the definition is
Learn to Use @dataclass in Python
Intro
I like Python’s tuple, which allows us to quickly bundle together values of different types as a single entity and manage them in an intuitive and easy-to-use way. However, I find that once the tuple has many fields, I’m forced to add a comment to indicate the meaning of each field. For example,
Use Github Actions to automate Hugo blog deployment
Intro
Recently I started learning the GitHub Actions, a feature provided by GitHub that can be used to automate a series of steps. In the process of software development, the most common use of this feature may be the building process. For static-typed programming languages such as C/C++, we are usually required to write the build scripts. The build process involves environment preparation, dependencies download, and build execution. However, automating software builds with GitHub Actions is not the focus of this post. As I was learning this feature, I thought about how I could put it into practice and realized I could use it to automate the build and deployment of my Hugo blog :)
Tail call and Tail-call Optimization (TCO)
Tail call & Tail-recursion
Assume that function A
calls function B
. We call function A
Caller and function B
Callee.
The tail call refers to when the Caller only needs to wait for the return value of the Callee, as everything else has already been completed1.
If this is a recursive function call(e.g. the Caller and Callee are the same function), then the function is said to be tail-recursive.
Learn to use text-object in Vim&Neovim
Intro
You probably do not know what the text-object is in Vim/Neovim. However, you may use it in your daily life. For instance, When you are writing code, you may want to change the arguments of a function. Take the following code as an example, let’s say you want to change the function call to bar(3, 2, 1)
, and the cursor currently stays on the ,