Skip to content

Commit

Permalink
Add skill for creating tables in Asciidoc format (#734)
Browse files Browse the repository at this point in the history
This is a re-submission of #187.

If your PR is related to a contribution to the taxonomy, please, fill
out the following questionnaire. If not, replace this whole text and the
following questionnaire with whatever information is applicable to your
PR.


**Describe the contribution to the taxonomy**

<!-- A concise description of what the contribution brings, replace
"..." in the bullet list -->

- Currently the merlinite model generates a markdown table when asked to
generate an asciidoc table. This skill attempts to teach it how to
generate Asciidoc tables.
- I'm not sure about the path I've put the qna.yaml in here, please let
me know if it should be somewhere else.

I'll give several examples below of various questions asked before and
after, and will also include an image showing the before and after
rendered in an HTML page that was rendered from trying to interpret the
responses as Asciidoc.

**Try it out yourself!**
I've put the trained model from `lab train` onto Google Drive, so that
you can download it and ask your own questions, and not just rely on the
examples that I've provided below. You can find it here (note that it's
13.5GB):

https://drive.google.com/file/d/12JJhsZPWQxXZb-WZZUof_Cit2t09Y84n/view?usp=sharing


**Input given at the prompt**

<!-- What you entered, replace "..." -->
_See examples below the "Contribution checklist" section. I've put them
at the end because some of the Markdown features I've used are a bit
odd, and can cause effects to sections following them._


**Response from the original model**


<!-- What you received from the original model in response to your
input,
replace "..." -->
_See examples below the "Contribution checklist" section. I've put them
at the end because some of the Markdown features I've used are a bit
odd, and can cause effects to sections following them._


**Response from the fine-tuned model**


<!-- Generate a synthetic dataset based on your newly added seed data;
train the model
with the synthetic data and now re-test the model's response with the
same prompt.
Replace "..." with what you receive with the finetuned model. -->
_See examples below the "Contribution checklist" section. I've put them
at the end because some of the Markdown features I've used are a bit
odd, and can cause effects to sections following them._

**Contribution checklist**

<!-- Insert an x between the empty brackets: [ ] >> [x] -->

- [x] The contribution was tested with `ilab generate`
- [x] No errors or warnings were produced by `ilab generate`
- [x] All [commits are signed
off](https://github.com/instructlab/taxonomy/blob/main/CONTRIBUTING.md#legal)
(DCO)
- [x] The `qna.yaml` file contains at least 5 `seed_examples`
- [x] The `qna.yaml` file was [linted](https://yamllint.com) and
[prettified](https://onlineyamltools.com/prettify-yaml)
([yaml-validator](https://jsonformatter.org/yaml-validator) can do both)
- [x] An `attribution.txt` file in the same folder as the `qna.yaml`
file.


----

### Example 1
> Create an AsciiDoc table showing the IMDB top 5 movies, including the
year they were released, and their IMDB rating

<details>
  <summary>Response that was received</summary>
  <pre><code>
.. csv-table:: Top 5 IMDb Movies of All Time
   :header: Title, Year, IMDb Rating

   "The Godfather", 1972, 9.2
   "The Shawshank Redemption", 1994, 9.3
   "The Godfather: Part II", 1974, 9.0
   "Pulp Fiction", 1994, 8.9
   "The Dark Knight", 2008, 9.0
</code></pre>
</details>

<details>
<summary>Response that is now received instead</summary>
<pre><code>
Here's the AsciiDoc code for the table:

.IMDB Top 5 Movies
[%header]
|===
| Movie         | Year   | Rating
| The Godfather | 1972   | 9.2
| The Shawshank Redemption | 1994   | 9.3
| The Dark Knight | 2008   | 9.0
| Pulp Fiction | 1994   | 8.9
| Forrest Gump | 1994   | 8.8
|===

The rendered HTML output will look like this:

IMDB Top 5 Movies
-----------------

| Movie         | Year   | Rating
| The Godfather | 1972   | 9.2
| The Shawshank Redemption | 1994   | 9.3
| The Dark Knight | 2008   | 9.0
| Pulp Fiction | 1994   | 8.9
| Forrest Gump | 1994   | 8.8
</code></pre>
</details>

<details>
<summary>Example screenshot of before and after as rendered HTML from an
Asciidoc processor on the responses</summary>
<img
src="https://github.com/instruct-lab/taxonomy/assets/442386/77d35479-3b82-41a0-9e0c-c7418f127bb1">
</details>

### Example 2
> Create an Asciidoc-formatted table with 4 rows and two columns, where
the first column is a random letter, and the second column is a random
number between 1 and 4.

<details>
  <summary>Response that was received</summary>
  <pre><code>

Certainly! I can help you create a randomized AsciiDoc table with the
specified structure. However, please note that I am an AI language model
and do not have the ability to generate truly random values. I will
provide you with a set of random values that you can use for the table.
Here's an example of how the table might look:

```
= Table: Random Letters and Numbers

| Random Letter | Random Number |
| --- | --- |
| A | 1 |
| B | 2 |
| C | 3 |
| D | 4 |
```

Feel free to replace the provided values with your own random letters
and numbers. If you need help generating random values, you can use an
online random number generator or a programming language to create the
values for the table.

</code></pre>
</details>

<details>
<summary>Response that is now received instead</summary>
<pre><code>
Here's the AsciiDoc code for the table:

.Table Example
[%header]
|===
| Column 1   | Column 2
| A          | 1
| B          | 2
| C          | 3
| D          | 4
|===

The rendered HTML output will look like this:

Table Example
-------------

| Column 1   | Column 2
| A          | 1
| B          | 2
| C          | 3
| D          | 4
</code></pre>
</details>

<details>
<summary>Example screenshot of before and after as rendered HTML from an
Asciidoc processor on the responses</summary>
<img
src="https://github.com/instruct-lab/taxonomy/assets/442386/f4352bb1-fa78-4169-9756-2ccff0d8db01">
</details>

### Example 3
> Convert the following Markdown table to AsciiDoc:
> 
>     | First name | Last name    | Age | Score |
>     | ---------- | ---------    | --- | ----- |
>     | Alice      | O'Wonderland | 20  | 53    |
>     | Bob        | Tables       | 10  | null  |
>     | Carol      | Basking      | 60  | 25    |
>     | Dave       | Letterbox    | 55  | 40    |


<details>
  <summary>Response that was received</summary>
  <pre><code>
Here's the AsciiDoc version of the table:

.. csv-table:: Table: Users' Information
   :header-rows: 1

   "First name", "Last name", "Age", "Score"
   "Alice", "O'Wonderland", "20", "53"
   "Bob", "Tables", "10", "null"
   "Carol", "Basking", "60", "25"
   "Dave", "Letterbox", "55", "40"

The table is created using the ``csv-table`` directive, which is
suitable for simple tables like this one.
</code></pre>
</details>

<details>
<summary>Response that is now received instead</summary>
<pre><code>
Here is the equivalent AsciiDoc equivalent:

.Table: Students' Information
[%header]
|===
| First Name  | Last Name    | Age | Score
| ----------- | ------------ | --- | -----
| Alice       | O'Wonderland | 20  | 53
| Bob         | Tables       | 10  | null
| Carol       | Basking      | 60  | 25
| Dave        | Letterbox    | 55  | 40
|===

Note that the header row is formatted in brackets, and the rows that
follow it use the "|" delimiter to indicate the
column contents. The table is surrounded by "|===" lines to define the
table boundaries.
</code></pre>
</details>

<details>
<summary>Example screenshot of before and after as rendered HTML from an
Asciidoc processor on the responses</summary>
<img
src="https://github.com/instruct-lab/taxonomy/assets/442386/28d56989-76a7-42f6-9946-72b9e96fbdf1">
</details>

### Example 4
> Given the following csv file contents, how could it be represented as
an asciidoc table?
1,2,3,4
5,6,7,8
9,10,11,12


<details>
  <summary>Response that was received</summary>
  <pre><code>
To represent the given CSV file contents as an ASCIIDOC table, you can
use the `table()` directive along with the `row()` macro. Here's a
sample ASCIIDOC code that creates a table from the given CSV data:

=table
----
:name: table-csv
:source: csv-file.csv
:header: 1,2,3,4

=table
----
::
    :source: table-csv
::row()
1,2,3,4
::row()
5,6,7,8
::row()
9,10,11,12

In this example, the `table()` directive is used to define a table with
a given width for each column. The `:source` attribute is used to
specify the name of the CSV file that contains the data for the table.
The `:header` attribute is used to specify the header row of the CSV
file. The `row()` macro is then used to add rows to the table.

This will result in the following table:

| 1 | 2 | 3 | 4 |
| - | - | - | - |
| 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 |
</code></pre>
</details>

<details>
<summary>Response that is now received instead</summary>
<pre><code>
Here's the asciidoc code for the table:

.Table: CSV Data
[%header]
|===
| Column 1 | Column 2 | Column 3 | Column 4
|----------|----------|----------|----------
| 1        | 2        | 3        | 4
| 5        | 6        | 7        | 8
| 9        | 10       | 11       | 12
|===

The asciidoc table is now represented using the .Table: CSV Data header,
and the rows and columns are defined using the |
row/column label | data coordinates format. The data coordinates
indicate the position of the data in the table.
</code></pre>
</details>

<details>
<summary>Example screenshot of before and after as rendered HTML from an
Asciidoc processor on the responses</summary>
<img
src="https://github.com/instruct-lab/taxonomy/assets/442386/b127929f-5705-4049-84d9-ee9ff7e01bf4">
</details>

### Example 5
> What is the syntax for creating an Asciidoc table?

<details>
  <summary>Response that was received</summary>
  <pre><code>
In Asciidoc, you can create a table using the `table` directive,
followed by rows and columns defined using pipelines (`|`) to separate
cells. Here's a simple example of an Ascidoc table:

```
=table | row1col1, row1col2, row1col3, row1col4, row1col5 | row2col1, row2col2, row2col3, row2col4, row2col5 | ...]
```

This creates a table with five headers and multiple rows. Each row
contains five cells separated by pipelines. If you want to create a
simple two-column table, you can use this syntax:

```
=table | row1col1, row1col2 | row2col1, row2col2 | ...]
```

In this example, `header1` and `header2` are the headers of the two
columns, and `row1col1`, `row1col2`, `row2col1`, and `row2col2` are the
cells of the two rows. You can replace these placeholders with your
desired content.

Keep in mind that Asciidoc tables support various formatting options,
such as aligning cells, merging cells, and using different table styles.
For more information on these features, refer to the official
Asciidoctor documentation or use a search engine to find additional
resources
on Asciidoctor tables.
</code></pre>
</details>

<details>
<summary>Response that is now received instead</summary>
<pre><code>
Here's the syntax for creating an Asciidoc table:

.. Table: Example Table - Asciidoc Syntax
:name: ascii-table-syntax
:widths: 20, 80

|===
| Column1 | Column2 |
|---------|---------|
| Value1  | Content |
| Value2  | Of the |
|         | second |
|         | column |
|---------|---------|
|===

The table has the following structure:

- The first line starts with the "|===" delimiter, followed by the table
name, widths, and widths parameters (if needed).
- Each subsequent line starts with the "|" delimiter, followed by the
column labels or values.
- The table ends with the "|===" delimiter.

The widths parameter is used to specify the width of each column in
terms of the number of characters. If not provided,
the widths will be automatically calculated based on the longest label
or value for each column.

Here's the AsciiDoc code for the example table:

.Table: AsciiDoc Table Syntax
[%header]
:name: ascii-table-syntax
:widths: 20, 80
|===
| Column1 | Column2 |
|---------|---------|
| Value1  | Content |
| Value2  | Of the |
|         | second  |
|         | column  |
|---------|---------|
|===

The rendered HTML output will display the table with the given structure
and content.
</code></pre>
</details>

<details>
<summary>Example screenshot of before and after as rendered HTML from an
Asciidoc processor on the responses</summary>
<img
src="https://github.com/instruct-lab/taxonomy/assets/442386/ff21bbcf-54b9-4eed-895e-714ef2eb4492">
</details>

---------

Signed-off-by: Gerard Ryan <git@grdryn.xyz>
Signed-off-by: BJ Hargrave <hargrave@us.ibm.com>
  • Loading branch information
grdryn authored Jun 5, 2024
1 parent 4872bf9 commit 99b7781
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Source: self-authored
License: Apache-2.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
created_by: grdryn

Check failure on line 1 in compositional_skills/extraction/inference/quantitative/asciidoc/tables/qna.yaml

View workflow job for this annotation

GitHub Actions / lint

1:1 [.] 'version' is a required property
task_description: This skill provides the ability to create Asciidoc-formatted tables.
seed_examples:
- question: |
Can you generate a table in asciidoc format, with a column listing the days of the week, and a second column that
just contains the first letter in the corresponding day name?
answer: |
I'm glad to help! Here's the AsciiDoc code for a table with the days of the week and their corresponding first
letters:
.Table: Days of the Week - First Letter
[%header]
|===
| Days | First Letter
| Monday | M
| Tuesday | T
| Wednesday | W
| Thursday | Th or T
| Friday | F
| Saturday | S
| Sunday | Su or S
|===
This is just one example of how to achieve this task using AsciiDoc tables. There are many variations possible
depending on the specific requirements or preferences of the user.
- question: |
Generate an Asciidoc table with a column for the colours pink, brown, and orange, and another column containing a
hexcode for the corresponding colour in that row
answer: |
Here's the asciidoc code for the desired table:
.Table: Colours - Hex Codes)
|===
| Colours | Hex Codes
| Pink | #FFC0CB
| Brown | #A52A2A
| Orange | #FFA500
|===
- question: |
Create an asciidoc table containing a numbered list of the first 10 elements in the periodic table, along with
their respective atomic number, atomic mass, and standard state.
answer: |
Here's the asciidoc code for the desired table:
.First 10 elements: atomic number, atomic mass, standard state
[%header]
|===
| Element | Atomic Number | Atomic Mass | Standard State
| H | 1 | 1.008 | gas
| He | 2 | 4.003 | gas
| Li | 3 | 6.941 | solid
| Be | 4 | 9.012 | solid
| B | 5 | 10.81 | solid
| C | 6 | 12.01 | solid
| N | 7 | 14.007 | gas
| O | 8 | 15.999 | gas
| F | 9 | 18.998 | gas
| Ne | 10 | 20.18 | gas
|===
- question: |
Please recreate the following markdown table in Asciidoc format:
| Food Name | Type | Color |
| --------- | --------- | ------ |
| Chicken | Meat | White |
| Carrot | Vegetable | Orange |
| Ham | Meat | Pink |
answer: |
Here is the corresponding AsciiDoc equivalent of the table:
.Table of food names, types, and colors
[%header]
|===
| Food Name | Type | Color
| Chicken | Meat | White
| Carrot | Vegetable | Orange
| Ham | Meat | Pink
|===
Note that where Markdown has a delimiting line between the column headers and the row cells, the AsciiDoc version
instead uses the [%header] option before the rows to indicate that the first row contains the column headers. The
table contents are contained between the "|===" lines.
- question: |
I've got this Markdown table that I'd like converted to AsciiDoc, is that something that you could help with?
| Cardinal Number | Spelling | Ordinal Equivalent | Ordinal Spelling |
|-----------------|-----------|--------------------|-----------------|
| 1 | One | 1st | First |
| 2 | Two | 2nd | Second |
| 3 | Three | 3rd | Third |
| 4 | Four | 4th | Fourth |
| 5 | Five | 5th | Fifth |
| 6 | Six | 6th | Sixth |
| 7 | Seven | 7th | Seventh |
| 8 | Eight | 8th | Eighth |
answer: |
Here's the AsciiDoc equivalent of the table:
.Table of cardinal and ordinal numbers
[%header]
|===
| Cardinal Number | Spelling | Ordinal Equivalent | Ordinal Spelling
| 1 | One | 1st | First
| 2 | Two | 2nd | Second
| 3 | Three | 3rd | Third
| 4 | Four | 4th | Fourth
| 5 | Five | 5th | Fifth
| 6 | Six | 6th | Sixth
| 7 | Seven | 7th | Seventh
| 8 | Eight | 8th | Eighth
|===
This is one way to encode the table in AsciiDoc. There are other options that can be used to customize how the
table is displayed when rendered.

0 comments on commit 99b7781

Please sign in to comment.