In short
TWIML AI Podcast Episode #672: Reasoning Over Complex Documents with DocLLM
Host: Sam Charrington Guest: Armineh Nourbakhsh, Executive Director at JP Morgan AI Research
Episode Summary In this episode, Armineh Nourbakhsh discusses the innovations and development of DocLLM, a layout-aware large language model (LLM) designed for multimodal document understanding. The conversation delves into the complexities of document AI, the unique approach taken in creating DocLLM, and the evaluation of its performance on various document understanding tasks.
Key Concepts and Discussions
- Background of Armineh Nourbakhsh
- Armineh has a background in unimodal NLP, working on tasks like information extraction and sentiment analysis.
- She transitioned to document AI after facing challenges in automating document review processes in her previous roles.
- Understanding Document AI
- Document AI focuses on processing enterprise documents such as annual reports, regulatory filings, invoices, and contracts.
- Distinction made between dense documents (e.g., financial reports) and sparse documents (e.g., invoices).
- Challenges in Current Document AI
- Traditional models often treat document layout information as secondary, leading to limitations in understanding complex documents.
- Encoder-only architectures dominate the market but have issues with robustness and efficiency when applying to diverse tasks.
- DocLLM Overview
- Architecture: Utilizes a generative model instead of an encoder-only approach, which allows for better adaptability across multiple tasks.
- Training Approach:
- Incorporates both textual semantics and spatial layout information for improved comprehension of document structure.
- Uses a fill-in-the-middle objective to enhance generative capabilities while maintaining context awareness.
- Core Tasks Addressed by DocLLM
- Key Information Extraction
- Visual Question Answering (VQA)
- Document Classification
- Tabular Reasoning
- Performance and Evaluation
- DocLLM excels in key information extraction and visual question answering tasks but struggles with tabular reasoning compared to state-of-the-art models like GPT-4.
- Evaluation highlights the importance of training on enterprise document datasets to improve robustness in specific contexts.
- Future Directions
- Plans to incorporate visual elements (e.g., graphs, charts) and improve model robustness for complex reasoning tasks.
- Exploration of different numeric representations to enhance tabular reasoning capabilities.
- Instruction Tuning Significance
- Enables the model to learn how to perform tasks without being tied to specific datasets, allowing for flexible application across different use cases.
- Ongoing validation of the model's performance against a larger benchmark of datasets to ensure versatility.
- Addressing Hallucination in LLMs
- Recognizes the challenge of hallucination in generative models and the importance of grounding answers in document text to mitigate risks.
- Technical Innovations and Optimizations
- Utilized advanced training techniques such as smart sample packing and bfloat16 precision to optimize the overall training process.
- Development of the model conducted on AWS with efficient resource management.
Key Takeaways
- DocLLM represents a significant advancement in document AI by effectively combining textual and spatial information in a layout-aware model.
- The challenges of multimodal understanding highlight the necessity for continuous evolution in model architecture and training methodologies.
- Future enhancements will focus on expanding the model's capabilities to handle more complex visual data and improve its reasoning abilities.
For a deeper exploration of the topics discussed in this episode, visit the complete show notes at [twimlai.com/go/672](https://twimlai.com/go/672).
Written by AI. May contain mistakes. Listen to the episode to check what was said.
Transcript
Automatic transcript. May contain errors.0:04All right, everyone. Welcome to another episode of the TwiML AI podcast. I am your host Sam Charrington. Today I'm joined by Armina Norbosh. Armina is an executive director at JPMorgan AI Research. Before we get going, be sure to take a moment to hit that follow button on Apple Podcasts, Spotify, or wherever you're listening to today's show. Armina, welcome to the podcast. Thank you for having me. I'm looking forward to digging into our conversation. We'll be talking about DocLLM, a pre-trained model that understands structured documents. But before we do, I'd love to have you share a little bit about your background and how you came to work in AI.
0:43Sure. So my background was actually in unimodal NLP. So very standard kind of NLP tasks, information extraction and sentiment analysis. And I came to work in NLP kind of by accident, by luck, I would like to say. So my undergraduate degree was in computer science. And after I graduated, I applied for scholarship at Nanyang Technological University in Singapore. And the scholarship program was pretty interesting. It was a master's degree, but it was a master's by research. And it was slightly different from standard programs where you apply, you know what program you're going to get into, potentially what faculty you're going to work with.
1:15You would just submit your resume in a cover letter and it would get circulated among different faculty. And they would pick you if your background matched their brand. And I was sure sending in my resume that if I got in, I would work with someone in the computer science department and I would be working on database optimization or some core metric like that. And then I got very lucky. Professor Chris Koo, who used to teach at the School of Journalism and Communication, picked my resume. And he wanted to work with targeted sentiment analysis of political news articles at the time. He really wanted to bring in NLP practices.
1:45How did you feel about that at the time? It was intriguing, I have to say. I think maybe it was because I'd mentioned in my resume that I was very interested in languages. And I actually used to teach as an ESL teacher. But it was very exciting because this is back in 2006. And sentiment is very much an unsolved problem in NLP. So it was exciting to work on that front. And I stayed after graduation, I worked in the industry for a decade, staying in core unimodal NLP before I made the switch to document AI. And really the first time I faced my first kind of serious multimodal document AI challenge was when I was working at S &P Global, trying to bring AI practices into the credit ratings business.
2:23And of course, part of the credit rating business is to have these highly skilled analysts look at sometimes 10, sometimes hundreds of pages of documentation from each client. And we were trying to automate some of that work for them. And it was very exciting because it was kind of at the frontier of my comfort zone. And it allowed me to flex my skills a little bit. And I guess the rest is history. I've been in Document AI ever since. The types of documents that you're focused on, I'm imagining, are things like annual reports and regulatory filings, perhaps news, but maybe less so news. Tell us a little bit about the way you think about the document AI landscape.
3:02Sure. So the way I would frame it is enterprise documents. That's our area of interest because, of course, documents could be very diverse. I mean, a restaurant menu is a document, right? But of course, as you said, we are very much focused on enterprise documents. I think of things that JP Morgan and S &P Global might be interested in. Again, like filings and annual reports might be different from expense reports and invoices and purchase orders, which are also enterprise documents. Is that fair? That is very fair. On the one end, you have these dense documents, like you said, financial reports and credit agreements and term sheets and so on.
3:43On the other end, you have very sparse form-like documents like invoices and receipts and tax forms, kind of carrying more visual structure as well as semantic structure, for sure. I've done a number of interviews on the space over the years, and I kind of would have thought it was a bit of a solved problem at this point. I know a lot of people think, hey, let's just apply OCR and that's it. But that's not the complete solution because of the structure, as you've mentioned, but apparently not. Tell us a little bit about that. Sure. I'm glad you asked that question because I do see that attitude sometimes from, say, maybe more kind of research-focused or academic communities about certain areas of.AI being quote-unquote solved.
4:26I actually started saying sentiment analysis was very much an unsolved problem in 2006. And you'd be surprised how unsolved it remains to this day. And the same would extend to DocAI, I would say, even maybe more so. So something that, for instance, really prompted us to think about DocA11 and became a main motivation for it was by early 2023, we were working in DocAI, my team and I, at JPMorgan for about three years. And we had created a suite of capabilities that actually had pretty competitive performance. But one challenge that we kept running into was the fact that the state of the art was dominated by encoder only architectures.
5:04So architectures that were following BERT and the BERTology suite of models. And of course, they have a stack of transformer encoders and they would adapt the mask language modeling objective to the multimodal domain. So they would have something called, say, mask visual language modeling, where instead of masking tokens in a sequence, you are masking visual tokens in a snippet of a document. or some other models would take a document and split it into patches. And then they would also take the text that was on the page and they would try to match each token to the corresponding patch. And that's how the model learned.
5:36That's kind of what I remember. Just going back a few years, one of the big innovations was, hey, before we were treating these documents as just text, and now we have this kind of Swiss army knife called a CNN, and we can start to apply it in different ways to our documents. And hey, now all of our problems are solved. but not quite solved. And we've advanced the tools that we're applying to the problem, it sounds like. Exactly. And I mean, to be fair, it is a very robust architecture, right? It has pretty decent performance. I think Layoutland version 3, which follows that architecture by Microsoft, is still a state of the art across many VRDU.
6:13VRDU stands for Visually Rich Document Understanding. Across many VRDU tasks, the issue we had, though, was, you know, you have to also to think about things like robustness and scaling and efficiency, right? And the issue we ran into was we would have a pre-trained model. And every time you want to apply it to a new task, you would have to fine-tune it. And one of the challenges these models have is the scale of the fine-tuning data set is much smaller compared to the scale of the pre-training data set. So the model, because it doesn't have a generative nature, it doesn't end up modeling the fine-tuning data set very well or very robustly.
6:48So you end up not having to fine tune it on different tasks, but also potentially having to fine tune it on every new distribution of data that you get. So if you have one pre-trained model and say 200 downstream tasks, you are creating 200 fine tuned versions of this model and deploying them independently, which was a problem at the time. And we want it to be more efficient. And I think it was in the spring 2023, it was already several months after ChatGPT was released and was met with huge success, that Dongsheng Wang, who's the lead author on the DACA alum paper, started asking this interesting question of, what if we had a foundational model?
7:23It could basically work with an individual interface being the prompting interface that you would only need to, at most, instruction to work with a suite of tasks. You would not need to create several copies of this model. And that's where really the team got started on this problem. So can you talk a little bit about how an LLM has been incorporated into the approach? You know, we think about LLMs, at least the kind of initial crop of LLMs were, you know, largely text-based. Now we're seeing more integration into multimodal scenarios. How are LLMs incorporated into what you're doing with Doc LLM?
8:04Sure. So as you said, the state-of-the-art LLMs at the time were mostly unimodal. We were just seeing some multimodal LLMs come out. And usually they follow the most successful, at least LLMs follow that autoregressive objective, right, of next token prediction. And we wanted to marry that objective with the layout information that we were getting from the document. So we started doing a pretty massive deep dive on the state-of-the-art literature, both on VRDU front and the LLM front. And we realized that there were a few gaps in the way the documents were being represented in both directions.
8:43One was, and this was not something that we discovered that was already being discussed in the literature. If you wanted to take a transformer based model or an LLM, whatever unimodal model you have, and you wanted to add multimodal signal to it, you had a choice of directly working with the image of a document if you're dealing with a scanned document, for instance. and a lot of the models out there were using these very fancy vision encoders as their backbone and analyses were starting to show that these vision encoders were very inefficient they were adding a lot of parameters to the size of the model but they weren't really doing much the model still kept relying on text is kind of kind of experiencing mode collapse so to speak and the reason was that these vision encoders their architecture was adapted directly from open domain visual question answering.
9:31And of course, if you want to do open domain VQA, it's a different ballgame. You have to exploit inductive biases that don't make a lot of sense in the.KI space, right? You have a much wider distribution of shading and lighting and colors and so on. You have to pay attention to contouring and all that. Whereas in documents, you have a pretty fixed color template usually, and the shading is pretty fixed. There is a grid structure that you can exploit in many forms that was not really being exploited. So a lot of the models actually started throwing away the vision aspect altogether. And that's actually what we also decided to do with DocLLM.
10:07But in future versions, we're hoping to look back at the vision encoder, adding a vision encoder as well. But we purely looked at the spatial and the textual content. The second aspect was that these multimodal models, they basically take unimodal information, say text and layout and vision, and they have to kind of fuse them somehow. Right. And what was happening was the text, the layout information was usually always treated as a second class citizen in a way. It was basically not modeled independently from any of the other modalities. It was just simply treated as, say, positional encodings and added to the text modality.
10:43And that ended up not being effective very much because the model didn't have an opportunity to learn kind of a mental map, for lack of a better term, of what layout means on its own. So we wouldn't learn disentangled representations of spatial versus textual information. And what we decided to do was basically allow the model to model each modality separately before fusing them together. So we have self-attention applied on the layout information, self-attention applied on text, and then we bring them together. And this is a very nice kind of architectural modification because it's plug and play.
11:19You could add it to any large language model backbone. And we, in fact, showed that you could do it with two different architectures, the Falcon architecture and the Llama 2 architecture. um the third and probably the biggest um contribution was that we realized that it's not so as i said earlier we really wanted a generative model that you could use um and to have a generative model you need to have a decoder architecture or an encoder decoder architecture the issue with these architectures is that they work very well and very robustly but only at massive scale. So at smaller scale, below a billion parameters, studies have shown that the encoder-only architecture is a lot more robust.
12:03And that's actually, that kind of makes sense when you think about it, because intuitively the tasks that encoder-only architectures are performing are a lot, quote-unquote, easier, right? They have access to the full context. They see the left context and the right context, whereas the next token prediction objective doesn't allow the model to look into the future. So the issue we had was in order to train a decoder architecture at very large scale so that it cannot perform the encoder-only architectures, you would need lots of data. And there is a fundamental issue of data availability in Document AI.
12:41The largest publicly available set of documents out there that is not licensed, not copyrighted, it's available for public consumption under fair use is the IIT-CDIP dataset, which is composed of, I believe, six or seven million documents from the tobacco industry. And this is the outcome of a lawsuit of the federal US government against the tobacco industry. So number one, a very biased dataset. Number two, very, very small collection compared to whatever we have available in the Unimodal literature, say the number of webpages on the World Wide Web or the number of Wikipedia entries. I would have thought that SEC report style documents would, you know, there would be an abundance of those as well.
13:28Does that not reach the size of this tobacco data set you're referring to? A very good question. It might. The issue with the SEC filings is that they do, because they are primarily XML based, their format is a lot more homogenous compared to what you get from the tobacco industry. They're not all that interesting because they are all the same. Yeah, they look very much the same, at least in terms of the color palette and content. So how do you, at medium scale, how do you make the model more robust? And this is something that we investigated and realized that and open AI had actually proposed something.
14:08I think there was a paper that came out in 2022 or one, if I'm not mistaken, around fill in the middle objectives. So this is almost like cheating. You have a decoder model, but you help it function as an encoder model. By not asking it to predict the next token, you take a sequence, you take a span in the middle of that sequence, you mask that span, and then move the true span to the end of the sequence. And given the full input sequence, you ask the model to generate the middle span. So the model still has access to the left and right context, but it's still working in a generative setting, which is a very nice setup.
14:46And there was actually, I think there was a GLM paper that came out that was kind of an advanced version of this fill in the middle of task. So instead of having one continuous span, you now mask multiple tokens in the middle of a sequence, move all of them to the end, shuffle them around so that they're not in order. So make the task a little harder for the model, but then still include some positional information so that the model knows, okay, now I I am filling position number three that was masked when I was reading the sequence. And that's something that we adapted to the doc LLM architecture.
15:20And it worked really well. Something that we also added on top of that was we have the multimodal space, right? We have an image of a page. So you can mask different tokens on the page. But usually, especially in sparse documents like forms, the text forms kind of natural blocks, right? Like an address forms a block, right? a paragraph forms a block, you could actually do the masking at the block level instead of the token level. And that makes it harder for the model because the model has to understand the entire block and what it needs to generate for that block. And remember, when it's seeing the sequence, it has no idea how many tokens are in the block.
15:56So it has to guess what the content is, where it is, what it looks like, how many tokens are there. And it kind of makes the task slightly harder, meaning the model learns a slightly more robust representation. You've made a couple of comments that were interesting. One is that you talked about how you wanted to, it was important to you to have a generative aspect to this model. You've also said, I think that you wanted to kind of move beyond next token prediction. Can you kind of frame out the tasks that you are hoping to achieve with what ultimately became DocL? I'm like, what core problems were you going after that you designed around?
16:40Yeah, there were four core VRD tasks that we were pursuing. There are more tasks in this space, but those were out of scope for us. The four core tasks were key information extraction, visual question answering, document classification, and tabular reasoning. And those are the four that we also evaluated the model on. Of course, there is page segmentation, there is optical character recognition, there's other tasks that you could look into, but we considered those out of scope because there are solutions out there that kind of do address our needs as people who need VRDU models for enterprise documents.
17:14But these were really the four core tasks where the state of the art was failing to give us what we needed. In spite of the fact that this is Doc LLM, you're not asking it to generate documents for you. You're not asking it to answer questions about documents. It's not like a rag style thing or anything like that it's more focused on kind of these core tasks that you mentioned? Yeah. So the base model is a generative model. So you could potentially instruction tune it for other tasks, but at least those were the tasks that we were targeting. And as you said, we do support visual question answering over documents, but not in a rag style manner where you are basically asked to retrieve and cobble together information from one or more documents.
18:00So that is one of the research directions that we are exploring at the moment. One of the tricks you employed was randomizing the position of the tokens that you were asking the model to predict during training, but then you also fed in the position information, which seems like it would kind of undermine the randomization. Like, how does that work? I think it teaches the model to consider the correct context when it's generating a certain token because you have to understand, especially when you put it into two-dimensional space in an image, it has to understand, okay, now I'm generating block number three and this is what was around block number three.
18:41So I have to be careful to generate something that is semantically consistent with what I was seeing in that region of the page. Another concept that comes up in this paper is the idea of graph machine learning or kind of this graphical structure of these documents. Is that part of the Doc LLM work? I know there's adjacent work or work kind of in the same family that is focused on that, but does this graph semantics come into play in Doc LLM? That's a very good question. So Doc LLM does not have a graph component, but graphs actually offer a really good opportunity to look at documents, especially the spatial information, because the spatial information can be encoded directly into the structure of the graph.
19:28And in fact, the Google cloud team has done some really good research on graph-based models. I believe form net is still state of the art in many form-based extraction tasks. We did also explore some graph representations for document understanding. There was a paper that came out at CIR last year named doc graph LM, where we try to explore that option and that direction. I think there's lots of room to explore in graph models, and we are hoping to spend more investment in there. The main challenge with graph architectures is that it's a little difficult to marry the local and the global kind of view of the graph, right?
20:09Usually the majority... Yeah, so we have kind of two families of graph learning approaches, right? The pre-deep learning, it was all about spectral qualities of the graph. You kind of try to learn the global topology of a graph and then create node representations that way. And then since the graph convolutional networks were popularized, it's more about the spatial properties where you have a message passing algorithm that basically is propagating information from one node to its neighbors and so on. And that message passing algorithm has a locality problem because, again, something that happens with a lot of sometimes even regular recurrent networks is over very long sequences, you tend to lose that message, right?
20:51So there hasn't been a really good, at least in the VRD literature, a very good kind of model that could balance these two views. And I think that's why first, I mean, it's not really trivial or simple, but for lack of a better term, for simpler tasks, such as key information extraction, where you just need local context, graphs tend to do really well. But when you go to more complex tasks, such as visual question answering, they're not there yet. Block infilling, is that what you described where you were infilling textual tokens, but at the end of the sequence? Or I guess the block had me thinking about spatial information as opposed to textual information.
21:33So we actually mask both. We mask the textual information and the spatial information. So the model has to predict both. But what we do provide is the ordering, right? So the model knows that this is block number five that I'm now generating. So it makes it a little more kind of spatially aware as well. You mentioned that one of the tasks that you focused on was focused on tabular data. Can you talk a little bit about how the model performs in that domain? I know that in previous conversations, one of the big challenges in dealing with enterprise documents is that you'll have tabular data in the middle of flowing text, and it really causes a lot of problems with the model.
22:17Can you talk a little bit about with DocLLM, kind of what you've seen there and anything that you've done to specifically accommodate those kinds of documents? Yeah, that's a really good question. And that's exactly right. The model almost has to context switch when it sees a table in a way that it doesn't need to in any other type of segment, like a bullet list or a paragraph. And the reason is for tables, you kind of need to pay attention in two directions, right? Whereas everywhere else, you're looking one way. So the reading order kind of changes. And each table has a different reading order.
22:50Some are more columnar, some need to be processed row-wise. So it makes it very challenging. And in fact, if you look at the evaluation section, I don't think tabular reasoning was where we did the best. Doc LLM did best in key information extraction tasks. But in visual question answering, I think we were 50-50 compared to state-of-the-art, including GPT-4. And then I think in tabular reasoning, we didn't come on top. And that could be one of the reasons. And that's something that we are actually looking at. Overall, when we did the instruction tuning exercises, we realized that there were a couple of angles that we could improve on and a couple of angles where we did really well on.
23:27So when more spatial reasoning was required over both text and spatial signal, we usually came up either first or second compared to the state of the art. When there was denser paragraphs that you had to do higher level reasoning, usually GPT-4 would come up top because it has very strong verbal reasoning skills. Now, we are doing a deep dive on the tabular reasoning data sets specifically because we're not sure if we were failing because of spatial information or we were failing because of something like quantitative reasoning that is very common in data sets that have tabular reasoning questions in them, right?
24:12Our model at the moment works best. What's an example that kind of illustrates the different failure modes? Sure. So, for example, consider that you have a financial report with an income statement, right? You could ask an extractive question that says, what was the net income in 2022? Or you could ask an abstractive question that says, what was the change in net income between 2022 and 2023? Right. And that would require spatial reasoning, followed by some quantitative calculations on top of it. And that's what Dr. LLM doesn't have out of the box as of now. So it works better for extractive settings and where more spatial reasoning is required rather than higher level reasoning, either verbal or quantitative.
24:51The other analysis that was kind of interesting, though, was that we did much better when the datasets were mostly composed of enterprise documents, the ones that you actually enumerated in the beginning. Whereas when we were working with data sets that included screenshots of web pages or Wikipedia tables or other kind of web-based content, we didn't do as well. And that could be because we were trained on a data set that was very heavily geared towards enterprise collection. So that could be another angle that we explore further. We couldn't find a really good, strong tabular reasoning document collection that was geared towards enterprise documents.
25:33We do have data sets such as FinQA, TACQA, all these quantitative reasoning data sets that are put together, but they're not focused on the spatial reasoning aspect of it. They're mostly focused on the quantitative reasoning aspect of it. So I guess that's something we could look at for future work. To what degree are you incorporating vision or pixels into this architecture and where? We are not. This.QLM works purely with text and bounding boxes as in spatial information. However, those bounding boxes are coming from somewhere, and that somewhere is an OCR engine. But it's like pre-processing as opposed to part of the model.
Read the full transcript
26:08Exactly. And we are looking at incorporating potentially visual information in the future, but the reason we kind of had this set up was because we limited ourselves to the one solution that is kind of universally available, which is Tesseract, which is an older model and it doesn't always perform well. So we basically decided to use the bare minimum. So we only get a sequence of tokens and words on the page, along with each word's bounding boxes. We don't look at any kind of semantic segmentation output that the OCR engine provides because we don't want to rely on something that only one solution provides.
26:42And so when you're talking about bounding boxes, they're at the token level as opposed to you're not getting a bounding box for a table, for example. Yes, we are not. One caveat, though, is for the block infilling, you do need to have block level information, right, or line level information. So during pre-training, we do use the line level information, not as input to the model, but we use them for masking, right, so that the model can generate those block level segments. But then during instruction tuning or an inference, you don't need to have any block level information. The model works perfectly fine with token level bounding.
27:18Is it kind of picking at semantics to question around calling this visual question answering if it's all text based? Ah, good question. So I guess visual question answering is kind of a standard term that's used in the literature. And we could definitely be a bit more kind of careful about the way we define it. But let me give you an example. So one of the data sets that we use to benchmark DocLM was DocVQA, so document visual question answering. And that dataset has a, not in the public test sets, but in their private test set, they have a really nice breakdown of the types of questions and how the questions are grounded in the body of the document.
27:56So they have some questions that only need verbal reasoning. So they're questions about what does this paragraph say or something. They have certain questions that have to do with reasoning over tables, reasoning over graphics and so on. And they have fully spatial VQA samples where you basically say, what is written at the bottom left corner of this page? What is written directly beneath that title? And that becomes a visual question answering challenge or task. But you could use spatial and text alone to address that question. You don't necessarily need all the pixel level visual information.
28:34You've mentioned instruction tuning a few times. Can you talk about the significance of instruction tuning in the model and any interesting learnings from that process? Yeah, I'm glad you asked that because I wanted to recognize Matthew Sebu, who is one of the core authors of.LLM. He ran a massive study on what kind of data sets we could use to benchmark.LLM on. And if you look at the literature, the majority of the VRD models are usually benchmarked against four to six data sets. And Matthew collected 16 data sets. He's still collecting more as we speak. So he's not done yet. He collected 16 data sets and he ran a massive instruction tuning campaign.
29:20Now, the great thing about instruction tuning as opposed to fine tuning is you don't train for a particular data set or distribution. You train for a particular task. So as long as the model knows how to perform a task, you can inject whatever taxonomy you have into the instruction. As an example, if you want to do key information extraction, one team or one end user might have a different taxonomy that they want to extract from, right? So they might be interested in dates and dresses, and another team might be interested in dates and names. So you don't teach the taxonomy to the model. You only teach how to do information extraction.
29:55You teach it, you know, if somebody tells you what is the value for X, extract X. X can be anything. And that's what really the scalability value that the models like Dalkel alum bring. So he performed instruction tuning for the four core tasks that I mentioned, visual question answering, key information extraction, document classification, and tabular reasoning. And he showed that the model was pretty robust across all, and it outperformed the state of the art in several. So that was a very kind of interesting outcome, and we're really hoping to continue using that as basically a unified API, so to speak, so that we can quickly adapt the model to different use cases.
30:31What are some of the future use cases that you're anticipating? We're still in what you would, I guess, call early beta. So very exploratory. We're trying to see how we can improve the model for real world use. A very simple example would be, you know, increasing the context window. We currently support a context window of about 1000 tokens, which is very standard. or the RAG model that you mentioned. We're looking at some of the RAG use cases. The other thing is it's very subtle differences in tasks can make a huge difference. So imagine a single span extraction task where you say, what is the address?
31:09And you extract the address versus a multi-span extraction task where you ask, what are all the addresses on this page? Suddenly you're in a different semantic domain and the model has to be a lot smarter. So we're trying to kind of gauge the robustness of the model in these various settings. What have you observed about the necessity or applicability of kind of prompt engineering techniques? You were kind of just suggesting this. Is the model very sensitive to the specific wording of prompts and you have to invest a lot of time to get it to do what you want? Or does the fact that it's limited to a somewhat narrow domain mean that it can infer more from a given prompt and give you good answers kind of independent of the specifics of the wording?
32:01Yeah. So something that I really appreciated about the way the team designed this model is we use two architectures as a backbone, Falcon for the 1 billion parameter model and Llama 2 for the 7 billion parameter model. And we didn't actually throw away the pre-training weights, the pre-trained weights of these models. We did continued pre-training. So So we loaded the weights and we added all the spatial information and continued pre-training on the IIT data set. And this helps the models that we've trained carry a lot of verbal reasoning with them into the downstream application. So they are somewhat robust against, you know, prompt engineering or kind of adversarial engineering techniques.
32:39What we have observed, though, is that one major challenge in using large language models, multimodal large language models, is that if they have a purely generative nature, they don't necessarily point you to where the answer comes from on the page, right? They don't quote unquote ground their answers. So you have to basically find either a post-processing mechanism or some other model that tries to find the correct grounding. And that helps a lot because that creates a much more reliable system, but that also can be used to, you know, mitigate risks such as hallucination. I was going to ask next about hallucination.
33:13Do you see any different characteristics in terms of hallucination, again, given the limited domain here, or is it kind of on par with other uses of LLMs? I would assume it is on par, but one thing I would say is we have a slight advantage, I guess, because of the domain. And that is, as I said, that is the fact that we worked with individual documents. And you can always try to find ways to ground the answer in the document and then profile hallucinations if they seem to be very far off from anything that's semantically happening in the document. So those are some of the approaches that we're exploring at the moment.
33:48Something that is interesting, you did have David Rosenberg talk about Bloomberg GPT, right, a while ago on the podcast. And what was really interesting was how the Bloomberg team looked at the way numbers were tokenized and realized that there was a real gap there in the way that large language models were treating numbers. And that is something that we've also noted could be a problem for multimodal models when they're dealing with numbers, because you have a very complex task of visual and spatial reasoning, and then you have that tokenization problem at the heart of it. So one thing that we're also looking at is what if different numeric representations can help, especially with tabular reasoning, when quantitative reasoning further complicates the problem.
34:30Do you have any ideas as far as what that might look like? Not yet. It's very early days, but of course, there's very good literature out there. There have been some very interesting studies recently that have noted that you could potentially divide your task into tasks that care about the very exact numeric values and then tasks that care about only about orders of magnitude. And if you actually represent your numbers as an order of magnitude representation, the model has a much easier time creating that quote unquote mental map. And that could be a direction we go because if you... Is that kind of like a quantization effect in some way?
35:07Exactly. It's very kind of rough representation. But when you think about it, if you do look at the document grounded question answering task as primarily a retrieval task, then order of magnitude representations might work because all you have to do is identify the cell where the right information is. And then once you've identified the cell, you could actually go back and look at the exact value of the number that was in that cell and use that for the calculation. So as long as you get the retrieval right, the rest of the process can carry on. How strongly do you feel that the particular approach to representing spatial information that you've landed on here is, quote unquote, the right approach?
35:52Meaning, do you think that you've demonstrated that it's just better than incorporating pixels or do you see opportunities to incorporate pixels later on? I think enterprise documents have different categories, right? The categories of data sets that we deal with today are mostly forms or reports or credit agreements, things that you mentioned. Those are not exactly very colorful documents, right? So they're not really meant to be designed in a fancy way and presented to an outsider audience. so they tend to be very austere for the back of a better term so we didn't really feel the need to bring in the visual information however in the future we're looking at adding more visual signal because we are interested in things like charts and graphs and infographics and investor presentations and things that will be you know very visually driven so we would like to definitely look at that regarding the spatial modality alone one thing that we did ablate on and we did demonstrate in the paper is that it wasn't necessarily sufficient to capture the entire semantic space in the document, but having that disentangled representation for sure helps.
36:59So we would advise against simply adding up the spatial information from the get-go to the textual information and having that simple early fusion. It is definitely worthwhile having self-attention over spatial information and then adding them to the textual information. Spatial information is coming from the bounding boxes that are associated with each of the tokens. And then now, how are you kind of pushing that through the pipeline and applying self-attention? So the spatial information, as you said, come from the bounding boxes. Then you have the token IDs. So the token IDs, of course, go through some form of text encoder, right?
37:38And the spatial information, you could project them into an embedding space. But once you do that, you want to enrich that embedding space using self-attention the same way that, you know, textual information has that luxury, right? You always have a self-attention layer. And you want to have that self-attention layer because you want the model to create that disentangled space of semantics, right? Let me give you an example. We understand the model by creating self-attention layers. It understands some meaning around text, right? That these words are similar to each other and all that. So in the spatial space, we wanted to understand things like if a bounding box is bigger than another one, the first one is probably some form of header.
38:15It doesn't matter what text is in it. It just indicates something semantically in the layout space. And we wanted to create that map before we add all that noise together and mix the two representations together. Is the spatial representation, is it much denser than the textual representation or are they kind of on par? You have to eventually project them into the same space if you want to add them together. So it's kind of on par. But the great thing is, the larger your hidden representations are, when you add them, simply add them together, they are likelier to be orthogonal to each other, so they don't basically confuse the model.
38:54Their addition does not – you don't lose much data by adding together. I think where that question was coming from was thinking about your example of, you know, the relative structure of text. It seemed at first glance that there are fewer things that you might want to or be able to represent spatially than with language. And I don't know if that's just because we're very keenly aware of the complexity of representing language and the richness of communication and maybe less so about what encoding might represent in terms of spatially with regards to these bounding boxes. Yeah, that's a fair point.
39:42And we could potentially look at probably different representations or sizes. But the good news is the model doesn't seem to suffer from creating sparser representations using larger embeddings. And as I said, one of the advantages might be that when you add it up with the text embeddings, you're not really adding noise to the text embeddings. They're orthogonal enough that they can work together. There was another related work or a couple of other related works that I think were historical biz graph QA and some work around synthetic document generation. Are they, to what degree are they kind of closely related to Doc LLM?
40:19They both point to the problem that I mentioned early on, which is there's really not a good large representative data set of documents that you can use for training. So our team has been very keenly aware of that. And two people on the team, Nasraj Rahman, who's also one of the core authors, as well as Peter Babkin, who's also one of the contributors to DocLLM, they had started thinking about this problem in two different directions. And Natraj was more interested in layout as a concept. And regardless of what text appears on a page, can you actually sample layout and generate synthetic layouts of very colorful, very diverse documents?
40:57And maybe we can have a sister project that just generates synthetic text, and then we can bring them together and generate all these synthetic enterprise documents. And that is specifically what he was interested in. In his publication, he focused on enterprise documents. Peter was thinking about diagrams and graphs and charts and how to generate those synthetically. And they actually worked together as part of the BizGraph QA data set because not only was Peter generating these synthetic diagrams, he wanted to embed them into realistic looking documents. so that they could, you know, whatever model wanted to do question answering over those diagrams, had to address all the challenges that we mentioned, context switching and being able to identify what is the correct region of the answer, being able to do retrieval, being able to do spatial reasoning.
41:44So we are really hoping to build on that direction and hopefully to diversify some of the data sets that we're working with today. You mentioned earlier the interview I did with David Rosenberg on Bloomberg GPT, one of the things that was really interesting in that interview was him talking about the scale that was needed to train this model. Was your effort similarly scaled in terms of the amount of GPUs, resources, et cetera, required to train the model? Yeah, that's a good question. So the challenge of data scale that I talked about earlier, it turns out it's kind of a blessing in disguise, because if you don't have much data, you don't have to create massive scale models.
42:28So our largest model, as you know, is 7 billion parameters, which is kind of a smaller size for an LLM. Nevertheless, the cost could, you know, balloon up very easily. So something that the team put a lot of effort on, not just from a cost savings perspective. I mean, you want to be mindful of the impact you have on the environment, right? What they really tried to do was Uber optimize the pipeline. So the main two contributors in that space were Dongsheng and Peter. Shout out two hugging face for the Accelerate library. Peter used the Accelerate library, the fully sharded parallel model, to parallelize the attention mechanisms and basically scale them across different GPUs.
43:04And Dongsheng did some smart sample packing for the mini batches, where, you know, of course, samples of similar size would be grouped together, so you don't need to do a lot of padding. But it's actually not a trivial problem in the multimodal space, because if you pack similar length documents together, you could be inadvertently enforcing a curriculum for your model. Because documents of very similar length could be forms from the same template, they could be the same text forms. And you don't want the model to get stuck in that local minima, so you had to do some smart sampling to be able to create good packing.
43:37And then we of course had bfloat 16 precision. So we did some quantization as well. And that ended up working. All of our pre-training and instruction tuning was done on a single G5 instance on AWS. A G5 instance has eight A10 GPUs with 24 gigabytes of memory each. And I think maybe the end-to-end process took about eight weeks, pre-training and instruction tuning. Anything else you would want to share in terms of future direction for this or things that you're looking forward to growing out of this project? Yeah, absolutely. One of the contributions we made was the instruction tuning data set, which we're actually hoping to release soon.
44:14On the model front itself, as I said, we are very interested in digging deeper into the types of errors the model makes, especially hallucination errors and improving its verbal reasoning qualities. And of course, you know, there's so much you can increase the context size of the model. So we would like to look at RAG as a potential solution for even dealing with single, very large documents, such as, you know, financial reports that could be hundreds of pages long. and of course, you know, we would like to branch out eventually into more complex visual documents such as charts and diagrams and so on.
44:49Well, Amina, thanks so much for chatting with us and sharing a bit about DocLLM and what your team's been working on. Thanks for having me.
From the publisher
Today we're joined by Armineh Nourbakhsh of JP Morgan AI Research to discuss the development and capabilities of DocLLM, a layout-aware large language model for multimodal document understanding. Armineh provides a historical overview of the challenges of document AI and an introduction to the DocLLM model. Armineh explains how this model, distinct from both traditional LLMs and document AI models, incorporates both textual semantics and spatial layout in processing enterprise documents like reports and complex contracts. We dig into her team’s approach to training DocLLM, their choice of a generative model as opposed to an encoder-based approach, the datasets they used to build the model, their approach to incorporating layout information, and the various ways they evaluated the model’s performance.
The complete show notes for this episode can be found at twimlai.com/go/672.




