yea for sure. Although there was a key issue I noticed, the wrong kwarg was being used to pass in the extractor function, so openai was extracting the graph every time
I see, let me change that really quick
changed it to kg_triplet_extract_fn=extract_triplets,
kg_triplet_extract_fn=extract_triplets_wiki,
It looks good! But note that it doesn't print the triplets found when using kg_triplet_extract_fn
unless your function is printing them 👍
I think you will noticed a larger difference in the knowledge graphs if you re-create the images after running with the updated kwarg
It might be interesting to dive a bit more into differences, but that's up to you 🙂
For the PR, tbh I would prefer something more similar to the version proposed in the colab I shared on the PR, since it removes some functions to make the notebook easier to digest 🙂 Of course, you can link to the full medium article or git repo too for more detailed usage
uhhhhhh, wrote the kwag wrong again.
wrote as kg_triplet_extractor_fn
no wonder it was getting those outputs
IBM 1401 is a computer system that was developed by IBM. It was introduced in 1959 and was one of the first fully transistorized computers. The IBM 1401 was designed for business use and became very popular, with thousands of units being sold worldwide. It was known for its reliability and ease of use, and it played a significant role in the early computerization of businesses. The IBM 1401 had a decimal-based architecture and used punched cards for input and output. It was also compatible with a wide range of peripherals and had a number of programming languages available for it, including FORTRAN and COBOL. The IBM 1401 was eventually replaced by newer computer systems, but it left a lasting impact on the industry.
this is the output from rebel
the openai was just oneline
IBM 1401 is a subject that is used for data processing. It is also located in a basement.
but the graph is off now for some reason for the pipeline
the wiki one still works,
took me too long to figure out why
for token in text.replace("%3Cs%3E", "")
lousy copying and pasting across platform
but now the query inference takes forever
query inference as in querying the index, or constructing it?
took 2 mins, still not loading, I was like what
Here's my extract function
def extract_triplets(input_text):
text = triplet_extractor.tokenizer.batch_decode(
[
triplet_extractor(input_text, return_tensors=True, return_text=False)[0][
"generated_token_ids"
]
]
)[0]
triplets = []
relation, subject, relation, object_ = '', '', '', ''
text = text.strip()
current = 'x'
for token in text.replace("<s>", "").replace("<pad>", "").replace("</s>", "").split():
if token == "<triplet>":
current = 't'
if relation != '':
triplets.append(
(
subject.strip(),
relation.strip(),
object_.strip()
)
)
relation = ''
subject = ''
elif token == "<subj>":
current = 's'
if relation != '':
triplets.append(
(
subject.strip(),
relation.strip(),
object_.strip()
)
)
object_ = ''
elif token == "<obj>":
current = 'o'
relation = ''
else:
if current == 't':
subject += ' ' + token
elif current == 's':
object_ += ' ' + token
elif current == 'o':
relation += ' ' + token
if subject != '' and relation != '' and object_ != '':
triplets.append(
(
subject.strip(),
relation.strip(),
object_.strip()
)
)
return triplets
I changed to your extracting func, now it works, but the output is short again
without wiki: IBM 1401 is a subject that is related to the predicate "manufacturer" and the object "IBM".
I suspect it might have been hallucinating before lol
a little too literal maybe haha
maybe need to play with retrieval techniques, waiting for the wiki one
i wonder if gpt-4
or gpt-3.5-turbo-instruct
would give better query results, at least in terms of being too literal
already am using "gpt-3.5-turbo"
yea, thats the bottom of the barrel for openai models
and the wiki one is awfully slow again, probably making hundreds of call to wikipedia, it seems like we have figured all of these out now,
I found caching the wiki responses helped quite a bit for runtime
caching the results under both the page title and canidate entity
show me a snippet for caching?
the graph looks very different
response with wiki: IBM 1401 is a subject that is related to the predicate “service entry” and the object “1401”. It is also related to the predicate “manufacturer” and the object “IBM”. Additionally, it is influenced by the programming language Fortran.
Yea it looks good though
For the caching, in my simplified notebook, I just did this
hmm the prompt may need some tweaking for gpt-3.5 lol
thanks, I will take a look
but now the medium article should be accurate
cool stuff, Logan you are great. Will do the example PR again later. and we can make it into the codebase as well?
Happy to help! Yea for sure we can get it in. I think for that though, I would prefer an example notebook closer to my simplified version, just to make things more digestable to anyone reading the notebook 💪
Make sense, I guess maybe we make it into code base first? Then just simply call it in the example ?
hmm, I think to make it into the codebase, it will need to be a bit more fully-featured. The example notebook is fairly concise at the moment, and maybe gives people ideas for further modifications, which is nice I think
For example, using existing wikipedia knowledge graphs and pulling out sub-grapghs as you go could be cool. :
https://github.com/google-deepmind/deepmind-research/tree/master/wikigraphs Then we go beyond filtering by adding an easy way to expand as well. Or maybe theres a way to fetch a graph for each matching page without an existing dataset, by looking at linked pages from the retrieved matching page
I like your notebook, do you wanna just put that one in and put a link to the medium if they wanna know more?
mind if I PR your notebook? I just ran it locally myself
or do you wanna change something? I don't know how git wokrs...
Yea pr my notebook! Full credits to you, I just noodled off of it 💪
accidentally uploaded my api key.... had to delete repo and do another PR
oh btw, I am looking for a job, would you guys be interested in bringing me on for full-time? or wanna wait and see for me to do more contributions? @jerryjliu0
yeah I know a bit abrupt, we can continue this conversation in a week, as I do more stuff. how does that sound?
I will dig into the deepmind repo
Logan, do you have any starting point for me, in terms of in using KG in a multi agent setting?
KG in a multi agent setting? Not really sure what that would look like 🤔
use KGindex as query engine
make it as a langchain tool
and use autogen to use the tool
and now we have auto llama
let's say 1. we build a KG Index on a few data science package, build as query_engine0
this will serve as a base for understandings. 2. Then make a few github repo loader query tool for active reference. 3. use autogen to solve data science problem
just think would be cool if we can combine autogen and llama index, one is auto generation, one is retrieval. then we have auto RAG, which is a fun tool to have
let me try to come up with something to show you what I mean
can't really figure out how to let autogen use llama index query engine as a funciton call
is there a place I can put this up in docs?
hi, I am trying to run KG index with Rebel following this code:
https://colab.research.google.com/drive/1G6pcR0pXvSkdMQlAK_P-IrYgo-_staxd?usp=sharing#scrollTo=NJrFdFSFLxXC.
But instead of using OpenAI gpt-3.5-turbo, I want to use Llama2 cpp as LLM (like in the picture) in the service context. But now I have problem with gpu cuda:
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with
TORCH_USE_CUDA_DSA
to enable device-side assertions.
Anyone has any idea how to fix it? thank you
set max_new_tokens to 256, set the context_window to 3900
@Logan M hi~~ been a while