You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by Mike Beckerle <mb...@apache.org> on 2023/04/25 16:27:50 UTC

Google bard scala coding assist - and other bard capabilities

So I got a free trial of google "bard", which is google's
large language-model AI thing.

It recently was updated and supports writing code now.

It supports Scala.

This is amazingly better than just web search. Consider this session, which
starts from my query which is completely useless as a regular web search:
Scala to validate an XML Schema, not to validate an XML file with an XML
Schema, but to validate the XML schema itself.
edit
View other drafts

Sure, here is a Scala program to validate an XML schema:
Scala

import scala.xml._import scala.xml.factory.XMLFactory
object SchemaValidator {
  def main(args: Array[String]) {
    val schemaFile = args(0)
    val schema = XMLFactory.parse(new File(schemaFile))

    // Validate the schema.
    val validator = new XmlSchemaValidator()
    if (!validator.validate(schema)) {
      println("The schema is invalid.")
      System.exit(1)
    }

    println("The schema is valid.")
  }
}
class XmlSchemaValidator {
  def validate(schema: Elem): Boolean = {
    // Create a schema factory.
    val factory = new XmlSchemaFactory()

    // Create a schema object from the schema document.
    val schemaObj = factory.newSchema(schema)

    // Validate the schema.
    schemaObj.validate(null)
  }
}

Use code with caution. Learn more <https://bard.google.com/faq#coding>
copy

This program works by first parsing the schema document into an XML
element. Then, it creates a schema factory and uses it to create a schema
object from the XML element. Finally, it validates the schema object. If
the schema is valid, the program prints "The schema is valid." If the
schema is invalid, the program prints "The schema is invalid" and exits
with a status code of 1.
Bard actually got this pretty close, which is that you construct a
factory.newSchema to validate the schema. I'm not sure about the final
validate call. I think that part is wrong, but this is already massively
better than web search.

I asked it to then write a Functional Specifications document for that
code, and the output is quite respectable:

Functional Specifications Document

Document Name: SchemaValidator

Version: 1.0

Date: 2023-04-25

1. Objective

The objective of this document is to specify the functional requirements
for the SchemaValidator Scala code.

2. Functional Requirements

The SchemaValidator Scala code must be able to:

   - Validate an XML Schema.
   - Print a success message if the schema is valid.
   - Print an error message if the schema is invalid.

3. Input

The SchemaValidator Scala code takes one input:

   - The name of the XML Schema file to validate.

4. Output

The SchemaValidator Scala code produces one output:

   - A success message if the schema is valid.
   - An error message if the schema is invalid.

5. Assumptions and Constraints

The SchemaValidator Scala code assumes that the following are true:

   - The XML Schema file is well-formed.
   - The XML Schema file is valid.

6. Functional Interface

The SchemaValidator Scala code must provide the following functional
interface:
Code snippet

def main(args: Array[String]): Unit

Use code with caution. Learn more <https://bard.google.com/faq#coding>
copy

7. Implementation

The SchemaValidator Scala code is implemented in Scala.

8. Testing

The SchemaValidator Scala code must be tested to ensure that it meets the
functional requirements specified in this document.

9. Documentation

The SchemaValidator Scala code must be documented to explain how to use it.

10. Maintenance

The SchemaValidator Scala code must be maintained to ensure that it
continues to meet the functional requirements specified in this document.
This is a respectable template, with schema validation plugged in, but item
5 bullet 2 is begging the question. This is about schema validating, so the
assumptions can't be that the schema is valid.
This does show ome of the limits of this sort of LLM AI. It glued these
concepts together, but nothing is actually reasoning about the sentences at
that level.

I will say, this language technology seems to be able to understand English
quite well.

E.g., I was pleasantly surprised that this query works well "I can use the
state department web site to get travel warnings. What does a Nigerian do?"

The Nigerian government has a website called the Nigerian Ministry of
Foreign Affairs (www.foreignaffairs.gov.ng) that provides travel warnings
and advisories for Nigerians traveling abroad. The website also provides
information on how to stay safe while traveling, including how to avoid
scams and how to get help if you are in trouble.

Here are some of the things that a Nigerian can do to get travel warnings:


   - Visit the Nigerian Ministry of Foreign Affairs website and check the
      travel warnings and advisories for the countries they plan to visit.
      - Subscribe to the Nigerian Ministry of Foreign Affairs's email list
      to receive updates on travel warnings and advisories.
      - Follow the Nigerian Ministry of Foreign Affairs on social media for
      updates on travel warnings and advisories.
      - Contact the Nigerian embassy or consulate in the country they plan
      to visit for more information on travel warnings and advisories.

It is important to remember that travel warnings and advisories are just
that: warnings. They are not meant to discourage people from traveling, but
to help them make informed decisions about their travel plans. If you are
planning to travel, it is always a good idea to check the travel warnings
and advisories for the countries you plan to visit.


It seems well able to figure out that I meant a Nigerian looking for
foreign travel warnings and points out their Nigerian government travel
advisory site for their citizens traveling abroad. Regular web search for
this does not get close to the right kind of answer.

I'm beginning to be a believer that this LLM AI stuff is useful. It passes
the Turing test better than many people. It has many limitations of course.

It is clearly WAY better than regular web searching.

One more example:
Which is correct: "If I were to go, I would need an umbrella." or "If I was
to go, I would need an umbrella." and explain why.

The correct sentence is "If I were to go, I would need an umbrella." This
is because the verb "to be" in the past subjunctive mood is used to express
a hypothetical situation. In this case, the speaker is not actually going
anywhere, but they are imagining what they would need if they did go.

The sentence "If I was to go, I would need an umbrella" is also
grammatically correct, but it is not the best choice in this context. The
past indicative mood is used to express something that actually happened or
is certain to happen. In this case, the speaker is not sure if they are
going anywhere, so the past subjunctive mood is the better choice.

Here are some more examples of the past subjunctive mood:


   - If I were rich, I would buy a house.
      - If I were you, I would go to the doctor.
      - If I were there, I would help you.

I hope this helps! Let me know if you have any other questions.