Posts

'Prompt Engineering for ChatGPT' course note: Part 3 Prompt Patterns

 Prompt patterns Prompt pattern is a pattern used to struct words in the prompt to solve a problem in LLM To achive different goals like: recognize input, format output, improve prompt, have interaction, limit scope. Example pattern: The Persona pattern "Act as ..., perform task Y": ask LLM as the professional or job title you know who can answer. You can ask a professional, an animal, an object. For example: Act as a professional standup comedian, whatever I tell you, make it into a joke. Example pattern: Helpful Assistant pattern prevent LLM from generating negative outputs "You are a helpful AI assistant. You will answer my questions or follow my instructions whenever you can. You will never answer my questions in a way that is insulting." Prompt pattern catalog From "A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT ", 2023. Define prompt pattern like software pattern. Define key ideas as a series of fundamental contextual statements....

'Learn LLVM 12' reading note: Part 2 The structure of a compiler

The structure of a compiler A compiler: Frontend (deal with source language) lexer parser semantic analyzer code generator (generate IR) Backend Target independent optimizatin Select instructions Target dependent optimization emit assembler code or object file   An arithmetic expression language (calc) An arithmetic expression language:  example: with a, b: a * (4 + b) language design using EBNF grammar non_terminal : rules having non-terminal, tokens example: calc : ("with" ident ("," ident)* ":")? expr ; EBNF grammer defines how lexer and parser should work, but not having semantic info lexer: create tokens void Lexer::next(Token& token); parser: create AST class AST {}; class Expr : public AST {}; class BinaryOp : public Expr {}; We create AST visitors to read and modify AST contents. class ASTVisitor { public : virtual void visit (AST&) {}; virtual void visit (Expr&) {}; virtual void visit (BinaryOp&) {}; }; ...

'Prompt Engineering for ChatGPT' course note: Part 2 What are Prompts

 What are prompts A prompt is a cue, a reminder to let LLVM remember something to say. A prompt can influence not only the current question, but also the future responses. Example: "From now on, when I ask a question, suggest a better version of my question and ask me if I would like to use it." You can provide additional info to help LLM analysis. Example: For ChatGPT 3.5 not knowing online info, provide new articles for it to parse answer. Intuitions behind prompts Based on training data and prompts, LLM predict the next word continuously. A strong pattern in training data can be a trap. We need to add specific words to escape or get into a trap. For example, "Mary has a little" is almost certainly to be followed by "lamb". If we don't want go into this trap, we can add word to skip it, like "Mary has a little microscopic". The prompt can provide pattern for output. It prompts LLVM to follow the pattern. For example:

‘Wheeled Autonomous Mobile Robot Programming in Practice’ reading note: Part 1 Wheeled Robot Basics

'Wheeled Autonomous Mobile Robot Programming in Practice' is the title of a book by Li De that was published in 2022. Wheeled Robot Basics Wheeled Robot moves by wheels, driven by electric motors, controlled by controllers like STM32 or Raspberry Pi. It needs electric motor drivers like L298N. Design a wheeled robot: 1. Planning: uses tools like FreeMind to make clear requirements (Robot dimensions, functions, work environments, special requirements). 2. Steering structure:    a. Differential steering: use different speed on left and right motors to turn.    b. Independent servo steering: use a servo to change direction of motors.    Differential steering is prefered: simple, can in-place turn.    Need a odometry motion model (based on the speed of the motors) to calculate current pose (x, y, θ).    Needs IMU sensor to calibrate. 3. Electric motor selection    12V power. To support odometry motion model, needs speed measur...

'Feynman's study method' reading note: Part 1 The essence of learning

 The essence of learning Traditional learning: input-oriented, measured by standard tests, driven by teachers. Output-oriented learning: Focus on output, Emphasize current impact, driven by teaching and usage. The essence of learning is output. Not the knowledge itself, but the use of the knowledge based on your situation. Five steps of output-oriented learning: establish a learning object, understanding the knowledge, teaching the knowledge, review, simplify. Establish a learning objective The object is dynamic, adjustable. Study should be easy, using a few understandable steps to make great progress. Use the limited time resource effectively on learning the selected object. Absorb it. To establish a learning object, ask yourself a few questions in two degrees: For the current situation: 1. What's the main problem? 2. What's the shortage? 3. How can I address shortcoming, how hard is it? 4. Split steps? For the future development: 1. What will I be interested in? 2. What are t...

'Prompt Engineering for ChatGPT' course note: Part 1 Motivation and Overview

 'Prompt Engineering for ChatGPT' is a coursera course. Motivation Large language models (LLM) like ChatGPT are not just for answering a question. It helps us design something, be creative. It's not one-off, but can keep refining in a direction. It can also connect two different things (like Pockman story and meal). It can prototype ideas like creating a demo web app. Overview This course teaches us how to interact with LLMs, how to write effective prompts. It's to unlock human creativity, let human focus on interesting things. It will teach different patterns of prompting. One is Persona pattern (Act as a ..., do ...). The most important thing is to be open to explore, to try things out. It's easy to get a conclusion that LLM doesn't help, but much harder to find a way to get benefit from LLM. We are trying to do the latter. What are Large language models Trained on massive inputs. Having hundreds of millions or even billions of parameters. It takes input, and ...

'Learn LLVM 12' reading note: Part 1 Building LLVM and standalone LLVM project

Building LLVM Install prerequisites, like git, ninja-build, cmake, ... Download LLVM from github Config the build using cmake:     cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=`pwd`/llvm-install ../llvm-project/llvm Then build it:   ninja install LLVM structure LLVM contents: LLVM core libs (in llvm/, has llc, llvm-objdump, llvm-dwarfdump, etc); compilers and tools (clang, lld, lldb, clang-format, clang-tidy, etc); runtime libs (compiler-rt, libunwind, libcxxabi, libcxx, libc, libclc). LLVM project layout: structured as a bunch of libraries depending on each other. Each project has libs, tools, utils (internal tools), unittests, docs, tests, includes. Building standalone LLVM projects It's more flexible to create standalone LLVM project, which can be built outside llvm. Use CMake configuration, pass LLVM_DIR to cmake to find llvm installation dir. Explanation is in...