首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写program程序、代做Python设计编程
项目预算:
开发周期:
发布时间:
要求地区:
HW: LLMs!
1/16
HW: LLMs, vectors, RAG :)
Summary
In this fi nal HW, you will:
use Weaviate [ ], which is a vector DB - stores data as vectors after vectorizing, and computes a search query by vectorizing it and does
similarity search with existing vectors
crawl the web using a Node package, to compile a 'knowledge base' [to use subsequently (not part of the hw) as input to build a (!)]
using a Python module, perform RAG [retrieval augmentation] on a 'small', locally-hosted LLM [make that an 'S'LM :)]
use to run RAG on their CPU+GPU platform
These are cutting-edge techniques to know, from a POV :) Plus, they are simply, FUN!!
Please make sure you have these installed, before starting: git, Docker, Node, Python (or Conda/Anaconda), [with 'Desktop development with C++'
checked].
Note: you need to do all four, Q1..Q4 (not pick just one!) :)
Q1.
Description
We are going to use vector-based similarity search, to retrieve search results that are not keyword-driven.
The (three) steps we need are really simple:
install Weaviate plus vectorizer via Docker as images, run them as containers
specify a schema for data, upload data/knowledge (in .json format) to have it be vectorized
run a query (which also gets vectorized and then sim-searched), get back results (as JSON)
The following sections describe the above steps.
1. Installing Weaviate and a vectorizer module
After installing Docker, bring it up (eg. on Windows, run Docker Desktop). Then, in your (ana)conda shell, run this docker-compose
command that uses this 'docker-compose.yml' confi g fi le to pull in two images: the 'weaviate' one, and a text2vec transformer
called 't2v-transformers':
docker-compose up -d
https://weaviate.io/
custom GPT
https://lightning.ai
future/career
VS 2022
yaml
HW: LLMs!
2/16
These screenshots show the progress, completion, and subsequently, two containers automatically being started (one for weaviate,
one for t2v-transformers):
HW: LLMs!
3/16
Yeay! Now we have the vectorizer transformer (to convert sentences to vectors), and weaviate (our vector DB search engine)
running! On to data handling :)
2. Loading data to search for
This is the data (knowledge, aka external memory, ie. prompt augmentation source) that we'd like searched, part of which will get
returned to us as results. The data is represented as an array of JSON documents. is our data file, conveniently named
data.json (you can rename it if you like) [you can visualize it better using ] - place it in the 'root' directory of
your webserver (see below). As you can see, each datum/'row'/JSON contains three k:v pairs, with 'Category', 'Question', 'Answer' as
keys - as you might guess, it seems to be in Jeopardy(TM) answer-question (reversed) format :) The fi le is actually called
, I simply made a local copy called data.json.
The overall idea is this: we'd get the 10 documents vectorized, then specify a query word, eg. 'biology', and automagically have that
pull up related docs, eg. the 'DNA' one (even if the search result doesn't contain 'biology' in it)! This is a really useful semantic search
feature where we don't need to specify exact keywords to search for.
Start by installing the weaviate Python client:
pip install weaviate-client
So, how to submit our JSON data, to get it vectorized? Simply use Python script, do:
python weave-loadData.py
Here
https://jsoncrack.com
jeopardy?tiny.json
this
HW: LLMs!
4/16
You will see this:
If you look in the script, you'll see that we are creating a schema - we create a class called 'SimSearch' (you can call it something else
if you like). The data we load into the DB, will be associated with this class (the last line in the script does this via add_data_object()).
NOTE - you NEED to run a local webserver [in a separate ana/conda (or other) shell], eg. via python - it's what will 'serve'
data.json to weaviate :)
Great! Now we have specifi ed our searchable data, which has been fi rst vectorized (by 't2v-transformers'), then stored as vectors (in
weaviate).
Only one thing left: querying!
3. Querying our vectorized data
To query, use this simple shell script called , and run this:
sh weave-doQuery.sh
As you can see in the script, we search for 'physics'-related docs, and sure enough, that's what we get:
'serveit.py'
weave-doQuery.sh
HW: LLMs!
5/16
Why is this exciting? Because the word 'physics' isn't in any of our results!
Now it's your turn:
? fi rst, MODIFY the contents of data.json, to replace the 10 docs in it, with your own data, where you'd replace ("Category","Question","Answer") with
ANYTHING you like, eg. ("Author","Book","Summary"), ("MusicGenre","SongTitle","Artist"), ("School","CourseName","CourseDesc"), etc, etc - HAVE fun
coming up with this! You can certainly add more docs, eg. have 20 of them instead of 10
? next, MODIFY the query keyword(s) in the query .sh fi le - eg. you can query for 'computer science' courses, 'female' singer, 'American' books,
['Indian','Chinese'] food dishes (the query list can contain multiple items), etc. Like in the above screenshot, 'cat' the query, then run it, and get a
screenshot to submit. BE SURE to also modify the data loader .py script, to put in your keys (instead of ("Category","Question","Answer"))
That's it, you're done :) In RL you will have a .json or fi le (or data in other formats) with BILLIONS of items! Later, do feel free to
play with bigger JSON fi les, eg. this Jeopardy JSON fi le :)
FYI/'extras'
Here are two more things you can do, via 'curl':
[you can also do ' ' in your browser]
[you can also do ' ' in your browser]
.csv
200K
http://localhost:8080/v1/meta
http://localhost:8080/v1/schema
HW: LLMs!
6/16
Weaviate has a cloud version too, called - you can try that as an alternative to using the Dockerized version:
Run :)
Also, for fun, see if you can print the raw vectors for the data (the 10 docs)...
More info:
?
?
?
?
Q2.
You are going to run a crawler on a set of pages that you know contain 'good' data - that could be used by an LLM to answer
questions 'intelligently' (ie. not confabulate, ie not 'hallucinate', ie. not make up BS based on its core, general-purpose pre-training!).
The crawled results get conveniently packaged into a single output.json fi le. For this qn, please specify what group of pages you
WCS
this
https://weaviate.io/developers/weaviate/quickstart/end-to-end
https://weaviate.io/developers/weaviate/installation/docker-compose
https://medium.com/semi-technologies/what-weaviate-users-should-know-about-docker-containers-1601c6afa079
https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-transformers
HW: LLMs!
7/16
crawled [you can pick any that you like], and, submit your output.json (see below for how to generate it).
Take a look:
You'll need to git-clone 'gpt-crawler' from . Then do 'npm install' to download the needed
Node packages. Then edit confi g.ts [ ] to specify your crawl path,
then simply run the crawler via npm.start! Voila - a resulting output.json, after the crawling is completed.
For this hw, you'll simply submit your output.json - but its true purpose is to serve as input for a cstom GPT :)
From builder.io's GitHub page:
Amazing! You can use this to create all sorts of SMEs [subject matter experts] in the future, by simply scraping existing docs on the
web.
Q3.
For this question, you are going to download a small (3.56G) model (with 7B parameters, compared to GPT-4's 1T for ex!), and use it
along with an external knowledge source (a simple text fi le) vectorized using Chroma (a popular vector DB), and ask questions
https://github.com/BuilderIO/gpt-crawler
https://github.com/BuilderIO/gpt-crawler/blob/main/confi g.ts
HW: LLMs!
8/16
whose answers would be found in the text fi le :) Fun!
git clone this: - and cd into it. You'll see a Python script (app.py) and a requirements.txt fi le.
Install pipenv:
https://github.com/afaqueumer/DocQA
HW: LLMs!
9/16
Install the required components (Chroma, LangChain etc) like so:
Turns out we need a newer version of llama-cpp-python, one of the modules we just installed - so do this:
HW: LLMs!
10/16
Next, let's grab this LLM: https://huggingface.co/TheBloke/Llama-2-7B-GGUF/blob/main/llama-2-7b.Q4_0.gguf - and save it to a
HW: LLMs!
11/16
models/folder inside your DocQA one:
Modify app.py to specify this LLM:
If you are curious about the .gguf format used to specify the LLM, read
Now we have all the pieces! These include the req'd Python modules, the LLM, and an app.py that will launch a UI via . Run
this.
'Streamlit'
HW: LLMs!
12/16
this [pipenv run streamlit run app.py]:
OMG - our chat UI in a browser, via a local webserver [the console prints info about the LLM]:
Now we need a simple text fi le to use for asking questions from (ie. 'external memory' for the LLM). I used
page, to make fi le, for ex.
We are now ready to chat with our doc! Upload the .txt, wait a few minutes for the contents to get vectorized and indexed :) When
https://www.coursera.org/articles/study-habits this
HW: LLMs!
13/16
that is done, ask a question - and get an answer! Like so:
That's quite impressive!
You would need to create a text fi le of your own [you could even type in your own text, about anything!], upload, ask a question,
then get a screenshot of the Q and A. You'd submit the text fi le and the screenshot.
The above is what the new 'magic' (ChatGPT etc) is about!! Later, you can try out , other language tasks, reading
PDF, etc. Such custom 'agents' are sure to become commonplace, serving/dispensing expertise/advice in myriad areas of life.
is more, related to Q3.
Q4.
This is a quick, easy and useful one!
Go to and sign up for a free account. Then read these: and
Browse through their vast collection of 'Studio' templates: - when you create (instantiate) one, you get
your own sandboxed environment [a 'cloud supercomputer'] that runs on lightning.ai's servers. You get unlimited CPU use, and 22
hours of GPU use per month (PLENTY, for beginner projects).
Create this Studio: - you are going to use this
to do RAG using your own PDF :)
Upload (drag and drop) your PDF [can be on ANY topic - coding, cooking, crafting, canoeing, cattle-ranching, catfi shing... (lol!)].
many other models
Here
HW: LLMs!
14/16
Eg. this shows the pdf I uploaded:
Next, edit run.ipynb, modify the 'fi les' variable to point to your pdf:
HW: LLMs!
15/16
Modify the 'query' var, and the 'queries' var, to each contain a QUESTION on which you'd like to do RAG, ie. get the answers from the
pdf you uploaded! THIS is the cool part - to be able to ask questions in natural language, rather than search by keyword, or look up
words in the index [if the pdf has an index].
Read through the notebook to understand what the code does and what the RAG architecture is, then run the code! You'll see the
two answers printed out. Submit screenshots of your pdf fi le upload, the two questions, and the two answers. The answers might
not be what you expected (ie might be imprecise, EVEN though it's RAG!) but that's ok - there are techniques to improve the quality
of the retrieval, you can dive into them later.
After the course, DO make sure to run (almost) all the templates! It's painless (zero installation!), fast (GPU execution!) and
useful/informative (well-documented!). It doesn't get more cutting edge than these, for 'IR'. You can even write and run your own
code in a Studio, and publish it as a template for others to use :)
HW: LLMs!
16/16
Getting help
There is a hw4 'forum' on Piazza, for you to post questions/answers. You can also meet w/the TAs, CPs, or me.
Have fun! This is a really useful piece of tech to know. Vector DBs are sure be used more and more in the near future, as a way to
provide 'infi nite external runtime memory' (augmentation) for pretrained LLMs. Read this too:
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
代做ece5550: applied kalman ...
2024-12-24
代做cp1402 assignment - netw...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!