# Create an AI assistant for lawyers

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%3E%5C
**Category:** 🤗 Course Projects\
**Created:** [November 9, 2021, 2:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512 "2021-11-09T14:57:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [November 9, 2021, 2:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F1 "2021-11-09T14:57:24Z")

</div>

> 👋 Please read the topic category [description](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fabout-the-course-projects-category%2F11510) to understand what this is all about

### Description

The Contract Understanding Atticus Dataset (CUAD) is a new dataset for legal contract review. Legal contracts often contain a small number of important clauses that warrant review by lawyers. This is a time-intensive task that requires specialised knowledge, so the goal of this project is to see if Transformer models can be used to extract answers to a predefined set of legal questions.

### Model(s)

Many of the `Question Answering` [models](https://huggingface.co/models?pipeline_tag=question-answering&sort=downloads) on the Hub could serve as a good baseline to get started. Given the specialised domain, you will probably want to try:

- Fine-tuning encoder-based models like BERT, RoBERTa, DeBERTa and friends
- Performing domain adaptation, by first fine-tuning the language model before tuning the question-answering head

### Datasets

[CUAD](https://huggingface.co/datasets/cuad) is available on the Hub.

### Challenges

This is a highly specialised domain, so a vanilla Transformer may not obtain great results.

### Desired project outcomes

Create a Streamlit of Gradio app on 🤗 Spaces that allows someone to select a legal contract, one or more questions, and provide the answer.

### Additional resources

- [CUAD announcement](https://www.atticusprojectai.org/cuadv1-announcement)
- [CUAD paper](https://arxiv.org/abs/2103.06268)
- [CUAD codebase](https://github.com/TheAtticusProject/cuad)

### Discord channel

To chat and organise with other people interested in this project, head over to our [Discord](http://xwo7x.mjt.lu/lnk/CAAAAkdkZwAAAAAAAAAAALG-MTEAAYCr4H8AAAAAAAyFyQBhjpnimM4rcE5DT5ibCUtRT96tWwAMh8Y/15/U6BYNMNDksyyGG4jgtzPKQ/aHR0cHM6Ly9odWdnaW5nZmFjZS5jby9qb2luL2Rpc2NvcmQ) and:

- Follow the instructions on the `#join-course` channel
- Join the `#ai-law-assistant` channel

Just make sure you comment here to indicate that you’ll be contributing to this project 🙂

---

<div class="post-metadata">

**Author:** ![pmarkovic](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@pmarkovic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpmarkovic)%5C
**Post date:** [November 14, 2021, 12:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F3 "2021-11-14T12:31:21Z")

</div>

Hi @lewtun, my name is Pavle and I would be interested in working on this project.

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [November 14, 2021, 2:52pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F4 "2021-11-14T14:52:02Z")

</div>

Hey @pmarkovic, I’ve just created a Discord channel (see topic description) in case you and others want to coordinate there 🙂

---

<div class="post-metadata">

**Author:** ![durgaamma2005](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/durgaamma2005/32/33493_2.png) [@durgaamma2005](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdurgaamma2005)%5C
**Post date:** [November 17, 2021, 7:27am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F6 "2021-11-17T07:27:51Z")

</div>

can somebody look at my notebook and help me to resolve the issue. [AI\_assistant\_law | Kaggle](https://www.kaggle.com/durgaamma2005/ai-assistant-law/edit)  
I am using blurr library which depends on fastai  
following is error trace of learn.summary()

````auto
/tmp/ipykernel_36/2746549787.py in <module>
----> 1 learn.summary()

/opt/conda/lib/python3.7/site-packages/fastai/callback/hook.py in summary(self)
    205 "Print a summary of the model, optimizer and loss function."
    206 xb = self.dls.train.one_batch()[:getattr(self.dls.train, "n_inp", 1)]
--> 207 res = module_summary(self, *xb)
    208 res += f"Optimizer used: {self.opt_func}\nLoss function: {self.loss_func}\n\n"
    209 if self.opt is not None:

/opt/conda/lib/python3.7/site-packages/fastai/callback/hook.py in module_summary(learn, *xb)
    173 # thus are not counted inside the summary
    174 #TODO: find a way to have them counted in param number somehow
--> 175 infos = layer_info(learn, *xb)
    176 n,bs = 76,find_bs(xb)
    177 inp_sz = _print_shapes(apply(lambda x:x.shape, xb), bs)

/opt/conda/lib/python3.7/site-packages/fastai/callback/hook.py in layer_info(learn, *xb)
    157 train_only_cbs = [cb for cb in learn.cbs if hasattr(cb, '_only_train_loop')]
    158 with learn.removed_cbs(train_only_cbs), learn.no_logging(), learn as l:
--> 159 r = l.get_preds(dl=[batch], inner=True, reorder=False)
    160 return h.stored
    161 

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in get_preds(self, ds_idx, dl, with_input, with_decoded, with_loss, act, inner, reorder, cbs, **kwargs)
    256 pred_i = 1 if with_input else 0
    257 if res[pred_i] is not None:
--> 258 res[pred_i] = act(res[pred_i])
    259 if with_decoded: res.insert(pred_i+2, getattr(self.loss_func, 'decodes', noop)(res[pred_i]))
    260 if reorder and hasattr(dl, 'get_idxs'): res = nested_reorder(res, tensor(idxs).argsort())

/opt/conda/lib/python3.7/site-packages/blurr/modeling/question_answering.py in activation(self, outs)
     77 
     78 def activation(self, outs):
---> 79 acts = [self.loss_funcs[i].activation(o) for i, o in enumerate(outs) ]
     80 return acts
     81 

/opt/conda/lib/python3.7/site-packages/blurr/modeling/question_answering.py in <listcomp>(.0)
     77 
     78 def activation(self, outs):
---> 79 acts = [self.loss_funcs[i].activation(o) for i, o in enumerate(outs) ]
     80 return acts
     81 

/opt/conda/lib/python3.7/site-packages/fastai/losses.py in activation(self, x)
     46 def __init__ (self, *args, axis=-1, **kwargs): super(). __init__ (nn.CrossEntropyLoss, *args, axis=axis,**kwargs)
     47 def decodes(self, x): return x.argmax(dim=self.axis)
---> 48 def activation(self, x): return F.softmax(x, dim=self.axis)
     49 
     50 # Cell

/opt/conda/lib/python3.7/site-packages/torch/nn/functional.py in softmax(input, dim, _stacklevel, dtype)
   1677 dim = _get_softmax_dim("softmax", input.dim(), _stacklevel)
   1678 if dtype is None:
-> 1679 ret = input.softmax(dim)
   1680 else:
   1681 ret = input.softmax(dim, dtype=dtype)

AttributeError: 'str' object has no attribute 'softmax' ```
````

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [November 17, 2021, 11:27am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F7 "2021-11-17T11:27:34Z")

</div>

Hey @durgaamma2005 I suggest opening an issue on the `blurr` GitHub repository since I’m sure they can help you with your query (I personally have no experience with `blurr`)

---

<div class="post-metadata">

**Author:** ![muhtasham](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/muhtasham/32/20892_2.png) [@muhtasham](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmuhtasham)%5C
**Post date:** [November 17, 2021, 10:22pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F8 "2021-11-17T22:22:29Z")

</div>

@lewtun can you hint at any data preprocessing for CUAD  
also i am using Colab with 25GB of ram, the session is crashing during the preprocessing step, is there any work around for this ?

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [November 17, 2021, 10:39pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F9 "2021-11-17T22:39:55Z")

</div>

Are you having trouble with the tokenizer or something else? If it’s the GPU RAM that’s the problem, one idea would be to reduce the batch size during training

---

<div class="post-metadata">

**Author:** ![muhtasham](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/muhtasham/32/20892_2.png) [@muhtasham](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmuhtasham)%5C
**Post date:** [November 17, 2021, 10:49pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F10 "2021-11-17T22:49:46Z")

</div>

i am having issue with preprocessing step before tokenizing the dataset because some of the questions have several possible answers, i am getting list index out of range

 ![Screenshot 2021-11-17 at 20.22.31](https://us1.discourse-cdn.com/hellohellohello/original/2X/4/4dbf4173295d6f664b95d406c97dd578b1d91dd0.png)

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [November 17, 2021, 11:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F11 "2021-11-17T23:05:48Z")

</div>

Hey @muhtasham one special aspect of CUAD is that it has long documents and produces a lot of passages for which there are no answers to be found. I suggest using the CUAD training script in their codebase (see topic description) as a starting point

---

<div class="post-metadata">

**Author:** ![Manel-Hik](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/manel-hik/32/20760_2.png) [@Manel-Hik](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FManel-Hik)%5C
**Post date:** [July 22, 2022, 5:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F12 "2022-07-22T17:25:49Z")

</div>

Hi @lewtun I’m interested in this project, Is there any resources about data processing how to build a training data with my own contracts ?? I checked in the CUAD github project but I can’t find it, I looked into discord for the #ai-law-assistant channel but can’t find it.  
could you help me please?  
thanks in advance

---

<div class="post-metadata">

**Author:** ![DukeC](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@DukeC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FDukeC)%5C
**Post date:** [July 23, 2022, 7:00pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F13 "2022-07-23T19:00:53Z")

</div>

[casetext.com](http://casetext.com) already does this very well.

---

<div class="post-metadata">

**Author:** ![Ayoola](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ayoola/32/3431_2.png) [@Ayoola](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAyoola)%5C
**Post date:** [July 29, 2022, 11:58am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F14 "2022-07-29T11:58:58Z")

</div>

I hope this project is still on going, as I am super interested.

---

<div class="post-metadata">

**Author:** ![drblbaker](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@drblbaker](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrblbaker)%5C
**Post date:** [February 21, 2023, 4:12am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fcreate-an-ai-assistant-for-lawyers%2F11512%2F15 "2023-02-21T04:12:59Z")

</div>

Interested in similar project for family firm. Following and willin\* to help.
