Skip to content

Commit

Permalink
Merge branch 'keras-team:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
achoum authored Feb 16, 2024
2 parents 0b3768e + ad92857 commit 49af161
Show file tree
Hide file tree
Showing 23 changed files with 549 additions and 701 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/csat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'CSAT survey'
on:
issues:
types:
- closed

permissions:
contents: read
issues: write
pull-requests: write

jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/github-script@v6
with:
script: |
const script = require('./\.github/workflows/scripts/csat.js')
script({github, context})
14 changes: 14 additions & 0 deletions .github/workflows/scripts/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let CONSTANT_VALUES = {
MODULE: {
CSAT: {
YES:'Yes',
NO:'No',
BASE_URL: 'https://docs.google.com/forms/d/e/1FAIpQLSdHag0RVFS7UXzZkKcsFCKOcX8raCupKK9RHSlYxp5U8lSJbQ/viewform?',
SATISFACTION_PARAM: 'entry.492125872=',
ISSUEID_PARAM: '&entry.243948740=',
MSG: 'Are you satisfied with the resolution of your issue?',
CSAT_LABELS: ['type:bug', 'type:build/install', 'type:support', 'type:others', 'type:docs-bug', 'type:performance', 'type:feature']
}
}
};
module.exports = CONSTANT_VALUES;
34 changes: 34 additions & 0 deletions .github/workflows/scripts/csat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

const CONSTANT_VALUES = require('./constant');
/**
* Invoked from staleCSAT.js and CSAT.yaml file to
* post survey link in closed issue.
* @param {!object} Object - gitHub and context contains the information about the
* current and context and github APIs using their built-in library functions.
*/
module.exports = async ({ github, context }) => {
const issue = context.payload.issue.html_url;
let base_url = CONSTANT_VALUES.MODULE.CSAT.BASE_URL;
//Loop over all ths label present in issue and check if specific label is present for survey link.
for (const label of context.payload.issue.labels) {
if (CONSTANT_VALUES.MODULE.CSAT.CSAT_LABELS.includes(label.name)) {
console.log(`label-${label.name}, posting CSAT survey for issue =${issue}`);
const yesCsat = `<a href="${base_url + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.YES +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + issue}"> ${CONSTANT_VALUES.MODULE.CSAT.YES}</a>`;

const noCsat = `<a href="${base_url + CONSTANT_VALUES.MODULE.CSAT.SATISFACTION_PARAM +
CONSTANT_VALUES.MODULE.CSAT.NO +
CONSTANT_VALUES.MODULE.CSAT.ISSUEID_PARAM + issue}"> ${CONSTANT_VALUES.MODULE.CSAT.NO}</a>`;
const comment = CONSTANT_VALUES.MODULE.CSAT.MSG + '\n' + yesCsat + '\n' +
noCsat + '\n';
let issueNumber = context.issue.number ?? context.payload.issue.number;
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}
}
};
52 changes: 52 additions & 0 deletions .github/workflows/scripts/stale_csat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

const csat = require('./csat.js');
const CONSTANT = require("./constant.js");
/**
*When stale bot closes the issue this function will
*invoke and post CSAT link on the issue.
*This function will fetch all the issues closed within 10 minutes and
*post the survey link if survey link is not posted already.
* @param {!object} Object - gitHub and context contains the information about
*the current and context and github APIs using their built-in library
*functions.
*/
module.exports = async ({ github, context }) => {
let date = new Date();
let totalMilliSeconds = date.getTime();
let minutes = 10;
let millisecondsToSubtract = minutes * 60 * 1000;
let closeTime = totalMilliSeconds-millisecondsToSubtract;
let newDate = new Date(closeTime);
let ISOCloseTime = newDate.toISOString();
// Fetch all the issue closed with in 10 mins.
let closeTimeIssues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state:"closed",
labels:"stale",
since:ISOCloseTime
});
let ISSUESLIST = closeTimeIssues.data;
console.log(`Fetching all the closed within ${minutes} minutes.`);
console.log(ISSUESLIST);
for(let i=0;i<ISSUESLIST.length;i++){
if(ISSUESLIST[i].node_id && ISSUESLIST[i].node_id.indexOf("PR") !=-1)
continue;
// Fetch last comments for the issues.
let comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ISSUESLIST[i].number
});
let noOfComments = comments.data.length;
let lastComment = comments.data[noOfComments-1];
let strCom = JSON.stringify(lastComment);
if(strCom.indexOf(CONSTANT.MODULE.CSAT.MSG) == -1){
context.payload.issue = {};
context.payload.issue.number = ISSUESLIST[i].number;
context.payload.issue.labels = ISSUESLIST[i].labels;
context.payload.issue.html_url = ISSUESLIST[i].html_url;
csat({github, context});
}
}
};
6 changes: 6 additions & 0 deletions .github/workflows/stale-issues-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ jobs:
close-issue-message: >
This issue was closed because it has been inactive for more than 1 year.
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
- uses: actions/github-script@v6
with:
script: |
const script = require('./\.github/workflows/scripts/stale_csat.js')
script({github, context})
2 changes: 1 addition & 1 deletion examples/graph/gnn_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def create_ffn(hidden_units, dropout_rate, name=None):
### Prepare the data for the baseline model
"""

feature_names = set(papers.columns) - {"paper_id", "subject"}
feature_names = list(set(papers.columns) - {"paper_id", "subject"})
num_features = len(feature_names)
num_classes = len(class_idx)

Expand Down
2 changes: 1 addition & 1 deletion examples/graph/ipynb/gnn_citations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
},
"outputs": [],
"source": [
"feature_names = set(papers.columns) - {\"paper_id\", \"subject\"}\n",
"feature_names = list(set(papers.columns) - {\"paper_id\", \"subject\"})\n",
"num_features = len(feature_names)\n",
"num_classes = len(class_idx)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/graph/md/gnn_citations.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def create_ffn(hidden_units, dropout_rate, name=None):


```python
feature_names = set(papers.columns) - {"paper_id", "subject"}
feature_names = list(set(papers.columns) - {"paper_id", "subject"})
num_features = len(feature_names)
num_classes = len(class_idx)

Expand Down
20 changes: 10 additions & 10 deletions examples/nlp/addition_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
Title: Sequence to sequence learning for performing number addition
Author: [Smerity](https://twitter.com/Smerity) and others
Date created: 2015/08/17
Last modified: 2020/04/17
Last modified: 2024/02/13
Description: A model that learns to add strings of numbers, e.g. "535+61" -> "596".
Accelerator: GPU
"""

"""
## Introduction
Expand Down Expand Up @@ -208,9 +209,14 @@ def decode(self, x, calc_argmax=True):
## Train the model
"""

# Training parameters.
epochs = 30
batch_size = 32

# Formatting characters for results display.
green_color = "\033[92m"
red_color = "\033[91m"
end_char = "\033[0m"

# Train the model each generation and show predictions against the validation
# dataset.
Expand All @@ -229,23 +235,17 @@ def decode(self, x, calc_argmax=True):
for i in range(10):
ind = np.random.randint(0, len(x_val))
rowx, rowy = x_val[np.array([ind])], y_val[np.array([ind])]
preds = np.argmax(model.predict(rowx), axis=-1)
preds = np.argmax(model.predict(rowx, verbose=0), axis=-1)
q = ctable.decode(rowx[0])
correct = ctable.decode(rowy[0])
guess = ctable.decode(preds[0], calc_argmax=False)
print("Q", q[::-1] if REVERSE else q, end=" ")
print("T", correct, end=" ")
if correct == guess:
print("☑ " + guess)
print(f"{green_color}{guess}{end_char}")
else:
print("☒ " + guess)
print(f"{red_color}{guess}{end_char}")

"""
You'll get to 99+% validation accuracy after ~30 epochs.
Example available on HuggingFace.
| Trained Model | Demo |
| :--: | :--: |
| [![Generic badge](https://img.shields.io/badge/🤗%20Model-Addition%20LSTM-black.svg)](https://huggingface.co/keras-io/addition-lstm) | [![Generic badge](https://img.shields.io/badge/🤗%20Spaces-Addition%20LSTM-black.svg)](https://huggingface.co/spaces/keras-io/addition-lstm) |
"""
21 changes: 10 additions & 11 deletions examples/nlp/ipynb/addition_rnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"**Author:** [Smerity](https://twitter.com/Smerity) and others<br>\n",
"**Date created:** 2015/08/17<br>\n",
"**Last modified:** 2020/04/17<br>\n",
"**Last modified:** 2024/02/13<br>\n",
"**Description:** A model that learns to add strings of numbers, e.g. \"535+61\" -> \"596\"."
]
},
Expand Down Expand Up @@ -290,9 +290,14 @@
},
"outputs": [],
"source": [
"# Training parameters.\n",
"epochs = 30\n",
"batch_size = 32\n",
"\n",
"# Formatting characters for results display.\n",
"green_color = \"\\033[92m\"\n",
"red_color = \"\\033[91m\"\n",
"end_char = \"\\033[0m\"\n",
"\n",
"# Train the model each generation and show predictions against the validation\n",
"# dataset.\n",
Expand All @@ -311,16 +316,16 @@
" for i in range(10):\n",
" ind = np.random.randint(0, len(x_val))\n",
" rowx, rowy = x_val[np.array([ind])], y_val[np.array([ind])]\n",
" preds = np.argmax(model.predict(rowx), axis=-1)\n",
" preds = np.argmax(model.predict(rowx, verbose=0), axis=-1)\n",
" q = ctable.decode(rowx[0])\n",
" correct = ctable.decode(rowy[0])\n",
" guess = ctable.decode(preds[0], calc_argmax=False)\n",
" print(\"Q\", q[::-1] if REVERSE else q, end=\" \")\n",
" print(\"T\", correct, end=\" \")\n",
" if correct == guess:\n",
" print(\"\u2611 \" + guess)\n",
" print(f\"{green_color}\u2611 {guess}{end_char}\")\n",
" else:\n",
" print(\"\u2612 \" + guess)"
" print(f\"{red_color}\u2612 {guess}{end_char}\")"
]
},
{
Expand All @@ -329,13 +334,7 @@
"colab_type": "text"
},
"source": [
"You'll get to 99+% validation accuracy after ~30 epochs.\n",
"\n",
"Example available on HuggingFace.\n",
"\n",
"| Trained Model | Demo |\n",
"| :--: | :--: |\n",
"| [![Generic badge](https://img.shields.io/badge/\ud83e\udd17%20Model-Addition%20LSTM-black.svg)](https://huggingface.co/keras-io/addition-lstm) | [![Generic badge](https://img.shields.io/badge/\ud83e\udd17%20Spaces-Addition%20LSTM-black.svg)](https://huggingface.co/spaces/keras-io/addition-lstm) |"
"You'll get to 99+% validation accuracy after ~30 epochs."
]
}
],
Expand Down
Loading

0 comments on commit 49af161

Please sign in to comment.